@rjsf/validator-ata 6.6.1

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.
Files changed (53) hide show
  1. package/README.md +94 -0
  2. package/dist/compileSchemaValidators.cjs +110 -0
  3. package/dist/compileSchemaValidators.cjs.map +7 -0
  4. package/dist/compileSchemaValidators.esm.js +79 -0
  5. package/dist/compileSchemaValidators.esm.js.map +7 -0
  6. package/dist/index.cjs +461 -0
  7. package/dist/index.cjs.map +7 -0
  8. package/dist/validator-ata.esm.js +450 -0
  9. package/dist/validator-ata.esm.js.map +7 -0
  10. package/dist/validator-ata.umd.js +422 -0
  11. package/lib/compileSchemaValidators.d.ts +16 -0
  12. package/lib/compileSchemaValidators.js +21 -0
  13. package/lib/compileSchemaValidators.js.map +1 -0
  14. package/lib/compileSchemaValidatorsCode.d.ts +13 -0
  15. package/lib/compileSchemaValidatorsCode.js +80 -0
  16. package/lib/compileSchemaValidatorsCode.js.map +1 -0
  17. package/lib/createAtaInstance.d.ts +27 -0
  18. package/lib/createAtaInstance.js +68 -0
  19. package/lib/createAtaInstance.js.map +1 -0
  20. package/lib/createPrecompiledValidator.d.ts +15 -0
  21. package/lib/createPrecompiledValidator.js +17 -0
  22. package/lib/createPrecompiledValidator.js.map +1 -0
  23. package/lib/customizeValidator.d.ts +8 -0
  24. package/lib/customizeValidator.js +9 -0
  25. package/lib/customizeValidator.js.map +1 -0
  26. package/lib/index.d.ts +7 -0
  27. package/lib/index.js +7 -0
  28. package/lib/index.js.map +1 -0
  29. package/lib/precompiledValidator.d.ts +89 -0
  30. package/lib/precompiledValidator.js +107 -0
  31. package/lib/precompiledValidator.js.map +1 -0
  32. package/lib/processRawValidationErrors.d.ts +28 -0
  33. package/lib/processRawValidationErrors.js +137 -0
  34. package/lib/processRawValidationErrors.js.map +1 -0
  35. package/lib/tsconfig.tsbuildinfo +1 -0
  36. package/lib/types.d.ts +63 -0
  37. package/lib/types.js +2 -0
  38. package/lib/types.js.map +1 -0
  39. package/lib/validator.d.ts +85 -0
  40. package/lib/validator.js +154 -0
  41. package/lib/validator.js.map +1 -0
  42. package/package.json +113 -0
  43. package/src/compileSchemaValidators.ts +30 -0
  44. package/src/compileSchemaValidatorsCode.ts +92 -0
  45. package/src/createAtaInstance.ts +81 -0
  46. package/src/createPrecompiledValidator.ts +29 -0
  47. package/src/customizeValidator.ts +16 -0
  48. package/src/index.ts +8 -0
  49. package/src/precompiledValidator.ts +188 -0
  50. package/src/processRawValidationErrors.ts +197 -0
  51. package/src/tsconfig.json +15 -0
  52. package/src/types.ts +71 -0
  53. package/src/validator.ts +231 -0
@@ -0,0 +1,15 @@
1
+ import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '@rjsf/utils';
2
+ import { Localizer, SuppressDuplicateFilteringType, ValidatorFunctions } from './types';
3
+ /** Creates and returns a `ValidatorType` interface that is implemented with a precompiled validator. If a `localizer`
4
+ * is provided, it is used to translate the messages generated by the underlying ata validation.
5
+ *
6
+ * NOTE: The `validateFns` parameter is an object obtained by importing from a precompiled validation file created via
7
+ * the `compileSchemaValidators()` function.
8
+ *
9
+ * @param validateFns - The map of the validation functions that are created by the `compileSchemaValidators()` function
10
+ * @param rootSchema - The root schema that was used with the `compileSchemaValidators()` function
11
+ * @param [localizer] - If provided, is used to localize a list of ata `ValidationError`s
12
+ * @param [suppressDuplicateFiltering] - Controls which duplicate filtering is suppressed; see `filterDuplicateErrors`
13
+ * @returns - The precompiled validator implementation resulting from the set of parameters provided
14
+ */
15
+ export default function createPrecompiledValidator<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validateFns: ValidatorFunctions, rootSchema: S, localizer?: Localizer, suppressDuplicateFiltering?: SuppressDuplicateFilteringType): ValidatorType<T, S, F>;
@@ -0,0 +1,17 @@
1
+ import ATAPrecompiledValidator from './precompiledValidator';
2
+ /** Creates and returns a `ValidatorType` interface that is implemented with a precompiled validator. If a `localizer`
3
+ * is provided, it is used to translate the messages generated by the underlying ata validation.
4
+ *
5
+ * NOTE: The `validateFns` parameter is an object obtained by importing from a precompiled validation file created via
6
+ * the `compileSchemaValidators()` function.
7
+ *
8
+ * @param validateFns - The map of the validation functions that are created by the `compileSchemaValidators()` function
9
+ * @param rootSchema - The root schema that was used with the `compileSchemaValidators()` function
10
+ * @param [localizer] - If provided, is used to localize a list of ata `ValidationError`s
11
+ * @param [suppressDuplicateFiltering] - Controls which duplicate filtering is suppressed; see `filterDuplicateErrors`
12
+ * @returns - The precompiled validator implementation resulting from the set of parameters provided
13
+ */
14
+ export default function createPrecompiledValidator(validateFns, rootSchema, localizer, suppressDuplicateFiltering) {
15
+ return new ATAPrecompiledValidator(validateFns, rootSchema, localizer, suppressDuplicateFiltering);
16
+ }
17
+ //# sourceMappingURL=createPrecompiledValidator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createPrecompiledValidator.js","sourceRoot":"","sources":["../src/createPrecompiledValidator.ts"],"names":[],"mappings":"AAEA,OAAO,uBAAuB,MAAM,wBAAwB,CAAC;AAG7D;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,UAAU,0BAA0B,CAKhD,WAA+B,EAC/B,UAAa,EACb,SAAqB,EACrB,0BAA2D;IAE3D,OAAO,IAAI,uBAAuB,CAAU,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,0BAA0B,CAAC,CAAC;AAC9G,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
2
+ import type { CustomValidatorOptionsType, Localizer } from './types';
3
+ import ATAValidator from './validator';
4
+ /** Build an `ATAValidator` instance, optionally customized with format
5
+ * checkers, validator overrides, an extender hook, or a localizer. Mirrors
6
+ * `@rjsf/validator-ajv8`'s `customizeValidator`.
7
+ */
8
+ export default function customizeValidator<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(options?: CustomValidatorOptionsType, localizer?: Localizer): ATAValidator<T, S, F>;
@@ -0,0 +1,9 @@
1
+ import ATAValidator from './validator';
2
+ /** Build an `ATAValidator` instance, optionally customized with format
3
+ * checkers, validator overrides, an extender hook, or a localizer. Mirrors
4
+ * `@rjsf/validator-ajv8`'s `customizeValidator`.
5
+ */
6
+ export default function customizeValidator(options = {}, localizer) {
7
+ return new ATAValidator(options, localizer);
8
+ }
9
+ //# sourceMappingURL=customizeValidator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customizeValidator.js","sourceRoot":"","sources":["../src/customizeValidator.ts"],"names":[],"mappings":"AAGA,OAAO,YAAY,MAAM,aAAa,CAAC;AAEvC;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAIxC,UAAsC,EAAE,EAAE,SAAqB;IAC/D,OAAO,IAAI,YAAY,CAAU,OAAO,EAAE,SAAS,CAAC,CAAC;AACvD,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import createPrecompiledValidator from './createPrecompiledValidator';
2
+ import customizeValidator from './customizeValidator';
3
+ export { customizeValidator, createPrecompiledValidator };
4
+ export { default as ATAValidator } from './validator';
5
+ export * from './types';
6
+ declare const _default: import("./validator").default<any, import("@rjsf/utils").RJSFSchema, any>;
7
+ export default _default;
package/lib/index.js ADDED
@@ -0,0 +1,7 @@
1
+ import createPrecompiledValidator from './createPrecompiledValidator';
2
+ import customizeValidator from './customizeValidator';
3
+ export { customizeValidator, createPrecompiledValidator };
4
+ export { default as ATAValidator } from './validator';
5
+ export * from './types';
6
+ export default customizeValidator();
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,0BAA0B,MAAM,8BAA8B,CAAC;AACtE,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,aAAa,CAAC;AACtD,cAAc,SAAS,CAAC;AAExB,eAAe,kBAAkB,EAAE,CAAC"}
@@ -0,0 +1,89 @@
1
+ import { CustomValidator, ErrorTransformer, FormContextType, RJSFSchema, StrictRJSFSchema, UiSchema, ValidationData, ValidatorType } from '@rjsf/utils';
2
+ import { RawValidationErrorsType } from './processRawValidationErrors';
3
+ import { CompiledValidateFunction, Localizer, SuppressDuplicateFilteringType, ValidatorFunctions } from './types';
4
+ /** `ValidatorType` implementation that uses an ata precompiled validator as created by the
5
+ * `compileSchemaValidators()` function provided by the `@rjsf/validator-ata` library.
6
+ */
7
+ export default class ATAPrecompiledValidator<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> implements ValidatorType<T, S, F> {
8
+ /** The root schema object used to construct this validator
9
+ *
10
+ * @private
11
+ */
12
+ readonly rootSchema: S;
13
+ /** The `ValidatorFunctions` map used to construct this validator
14
+ *
15
+ * @private
16
+ */
17
+ readonly validateFns: ValidatorFunctions;
18
+ /** The main validator function associated with the base schema in the `precompiledValidator`
19
+ *
20
+ * @private
21
+ */
22
+ readonly mainValidator: CompiledValidateFunction;
23
+ /** The Localizer function to use for localizing ata errors
24
+ *
25
+ * @private
26
+ */
27
+ readonly localizer?: Localizer;
28
+ /** Controls which duplicate error filtering is suppressed; see `filterDuplicateErrors`
29
+ *
30
+ * @private
31
+ */
32
+ readonly suppressDuplicateFiltering?: SuppressDuplicateFilteringType;
33
+ /** Constructs an `ATAPrecompiledValidator` instance using the `validateFns` and `rootSchema`
34
+ *
35
+ * @param validateFns - The map of the validation functions that are generated by the `schemaCompile()` function
36
+ * @param rootSchema - The root schema that was used with the `compileSchema()` function
37
+ * @param [localizer] - If provided, is used to localize a list of ata `ValidationError`s
38
+ * @param [suppressDuplicateFiltering] - Controls which duplicate filtering is suppressed; see `filterDuplicateErrors`
39
+ * @throws - Error when the base schema of the precompiled validator does not have a matching validator function
40
+ */
41
+ constructor(validateFns: ValidatorFunctions, rootSchema: S, localizer?: Localizer, suppressDuplicateFiltering?: SuppressDuplicateFilteringType);
42
+ /** Returns the precompiled validator associated with the given `schema` from the map of precompiled validator
43
+ * functions.
44
+ *
45
+ * @param schema - The schema for which a precompiled validator function is desired
46
+ * @returns - The precompiled validator function associated with this schema
47
+ */
48
+ getValidator(schema: S): CompiledValidateFunction;
49
+ /** Ensures that the validator is using the same schema as the root schema used to construct the precompiled
50
+ * validator. It first compares the given `schema` against the root schema and if they aren't the same, then it
51
+ * checks against the resolved root schema, on the chance that a resolved version of the root schema was passed in
52
+ * instead of the raw root schema.
53
+ *
54
+ * @param schema - The schema against which to validate the form data
55
+ * @param [formData] - The form data to validate if any
56
+ */
57
+ ensureSameRootSchema(schema: S, formData?: T): boolean;
58
+ /** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use
59
+ * by the playground. Returns the `errors` from the validation
60
+ *
61
+ * @param schema - The schema against which to validate the form data
62
+ * @param [formData] - The form data to validate, if any
63
+ * @throws - Error when the schema provided does not match the base schema of the precompiled validator
64
+ */
65
+ rawValidation<Result = any>(schema: S, formData?: T): RawValidationErrorsType<Result>;
66
+ /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives
67
+ * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also
68
+ * supports a `transformErrors` function that will take the raw ata validation errors, prior to custom validation and
69
+ * transform them in what ever way it chooses.
70
+ *
71
+ * @param formData - The form data to validate
72
+ * @param schema - The schema against which to validate the form data
73
+ * @param [customValidate] - An optional function that is used to perform custom validation
74
+ * @param [transformErrors] - An optional function that is used to transform errors after ata validation
75
+ * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`
76
+ */
77
+ validateFormData(formData: T | undefined, schema: S, customValidate?: CustomValidator<T, S, F>, transformErrors?: ErrorTransformer<T, S, F>, uiSchema?: UiSchema<T, S, F>): ValidationData<T>;
78
+ /** Validates data against a schema, returning true if the data is valid, or false otherwise. If the schema is
79
+ * invalid, then this function will return false.
80
+ *
81
+ * @param schema - The schema against which to validate the form data
82
+ * @param formData - The form data to validate
83
+ * @param rootSchema - The root schema used to provide $ref resolutions
84
+ * @returns - true if the formData validates against the schema, false otherwise
85
+ * @throws - Error when the schema provided does not match the base schema of the precompiled validator OR if there
86
+ * isn't a precompiled validator function associated with the schema
87
+ */
88
+ isValid(schema: S, formData: T | undefined, rootSchema: S): boolean;
89
+ }
@@ -0,0 +1,107 @@
1
+ import { deepEquals, hashForSchema, ID_KEY, JUNK_OPTION_ID, retrieveSchema, } from '@rjsf/utils';
2
+ import get from 'lodash/get';
3
+ import processRawValidationErrors from './processRawValidationErrors';
4
+ /** `ValidatorType` implementation that uses an ata precompiled validator as created by the
5
+ * `compileSchemaValidators()` function provided by the `@rjsf/validator-ata` library.
6
+ */
7
+ export default class ATAPrecompiledValidator {
8
+ /** Constructs an `ATAPrecompiledValidator` instance using the `validateFns` and `rootSchema`
9
+ *
10
+ * @param validateFns - The map of the validation functions that are generated by the `schemaCompile()` function
11
+ * @param rootSchema - The root schema that was used with the `compileSchema()` function
12
+ * @param [localizer] - If provided, is used to localize a list of ata `ValidationError`s
13
+ * @param [suppressDuplicateFiltering] - Controls which duplicate filtering is suppressed; see `filterDuplicateErrors`
14
+ * @throws - Error when the base schema of the precompiled validator does not have a matching validator function
15
+ */
16
+ constructor(validateFns, rootSchema, localizer, suppressDuplicateFiltering) {
17
+ this.rootSchema = rootSchema;
18
+ this.validateFns = validateFns;
19
+ this.localizer = localizer;
20
+ this.suppressDuplicateFiltering = suppressDuplicateFiltering;
21
+ this.mainValidator = this.getValidator(rootSchema);
22
+ }
23
+ /** Returns the precompiled validator associated with the given `schema` from the map of precompiled validator
24
+ * functions.
25
+ *
26
+ * @param schema - The schema for which a precompiled validator function is desired
27
+ * @returns - The precompiled validator function associated with this schema
28
+ */
29
+ getValidator(schema) {
30
+ const key = get(schema, ID_KEY) || hashForSchema(schema);
31
+ const validator = this.validateFns[key];
32
+ if (!validator) {
33
+ throw new Error(`No precompiled validator function was found for the given schema for "${key}"`);
34
+ }
35
+ return validator;
36
+ }
37
+ /** Ensures that the validator is using the same schema as the root schema used to construct the precompiled
38
+ * validator. It first compares the given `schema` against the root schema and if they aren't the same, then it
39
+ * checks against the resolved root schema, on the chance that a resolved version of the root schema was passed in
40
+ * instead of the raw root schema.
41
+ *
42
+ * @param schema - The schema against which to validate the form data
43
+ * @param [formData] - The form data to validate if any
44
+ */
45
+ ensureSameRootSchema(schema, formData) {
46
+ if (!deepEquals(schema, this.rootSchema)) {
47
+ // Resolve the root schema with the passed in form data since that may affect the resolution
48
+ const resolvedRootSchema = retrieveSchema(this, this.rootSchema, this.rootSchema, formData);
49
+ if (!deepEquals(schema, resolvedRootSchema)) {
50
+ throw new Error('The schema associated with the precompiled validator differs from the rootSchema provided for validation');
51
+ }
52
+ }
53
+ return true;
54
+ }
55
+ /** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use
56
+ * by the playground. Returns the `errors` from the validation
57
+ *
58
+ * @param schema - The schema against which to validate the form data
59
+ * @param [formData] - The form data to validate, if any
60
+ * @throws - Error when the schema provided does not match the base schema of the precompiled validator
61
+ */
62
+ rawValidation(schema, formData) {
63
+ this.ensureSameRootSchema(schema, formData);
64
+ this.mainValidator(formData);
65
+ if (typeof this.localizer === 'function') {
66
+ this.localizer(this.mainValidator.errors);
67
+ }
68
+ const errors = this.mainValidator.errors || undefined;
69
+ // Clear errors to prevent persistent errors, see #1104
70
+ this.mainValidator.errors = null;
71
+ return { errors: errors };
72
+ }
73
+ /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives
74
+ * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also
75
+ * supports a `transformErrors` function that will take the raw ata validation errors, prior to custom validation and
76
+ * transform them in what ever way it chooses.
77
+ *
78
+ * @param formData - The form data to validate
79
+ * @param schema - The schema against which to validate the form data
80
+ * @param [customValidate] - An optional function that is used to perform custom validation
81
+ * @param [transformErrors] - An optional function that is used to transform errors after ata validation
82
+ * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`
83
+ */
84
+ validateFormData(formData, schema, customValidate, transformErrors, uiSchema) {
85
+ const rawErrors = this.rawValidation(schema, formData);
86
+ return processRawValidationErrors(this, rawErrors, formData, schema, customValidate, transformErrors, uiSchema, this.suppressDuplicateFiltering);
87
+ }
88
+ /** Validates data against a schema, returning true if the data is valid, or false otherwise. If the schema is
89
+ * invalid, then this function will return false.
90
+ *
91
+ * @param schema - The schema against which to validate the form data
92
+ * @param formData - The form data to validate
93
+ * @param rootSchema - The root schema used to provide $ref resolutions
94
+ * @returns - true if the formData validates against the schema, false otherwise
95
+ * @throws - Error when the schema provided does not match the base schema of the precompiled validator OR if there
96
+ * isn't a precompiled validator function associated with the schema
97
+ */
98
+ isValid(schema, formData, rootSchema) {
99
+ this.ensureSameRootSchema(rootSchema, formData);
100
+ if (get(schema, ID_KEY) === JUNK_OPTION_ID) {
101
+ return false;
102
+ }
103
+ const validator = this.getValidator(schema);
104
+ return validator(formData);
105
+ }
106
+ }
107
+ //# sourceMappingURL=precompiledValidator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"precompiledValidator.js","sourceRoot":"","sources":["../src/precompiledValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EAGV,aAAa,EACb,MAAM,EACN,cAAc,EACd,cAAc,GAMf,MAAM,aAAa,CAAC;AAErB,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,0BAAuD,MAAM,8BAA8B,CAAC;AAGnG;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAuB;IAmC1C;;;;;;;OAOG;IACH,YACE,WAA+B,EAC/B,UAAa,EACb,SAAqB,EACrB,0BAA2D;QAE3D,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,0BAA0B,GA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IAAI,CAAC,aAAa,CAAC,MAAM,IAAI,SAAS,CAAC;QAEtD,uDAAuD;QACvD,IAAI,CAAC,aAAa,CAAC,MAAM,GAAG,IAAI,CAAC;QAEjC,OAAO,EAAE,MAAM,EAAE,MAA6B,EAAE,CAAC;IACnD,CAAC;IAED;;;;;;;;;;OAUG;IACH,gBAAgB,CACd,QAAuB,EACvB,MAAS,EACT,cAAyC,EACzC,eAA2C,EAC3C,QAA4B;QAE5B,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAkB,MAAM,EAAE,QAAQ,CAAC,CAAC;QACxE,OAAO,0BAA0B,CAC/B,IAAI,EACJ,SAAS,EACT,QAAQ,EACR,MAAM,EACN,cAAc,EACd,eAAe,EACf,QAAQ,EACR,IAAI,CAAC,0BAA0B,CAChC,CAAC;IACJ,CAAC;IAED;;;;;;;;;OASG;IACH,OAAO,CAAC,MAAS,EAAE,QAAuB,EAAE,UAAa;QACvD,IAAI,CAAC,oBAAoB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAChD,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,cAAc,EAAE,CAAC;YAC3C,OAAO,KAAK,CAAC;QACf,CAAC;QACD,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAC5C,OAAO,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC;CACF"}
@@ -0,0 +1,28 @@
1
+ import { CustomValidator, ErrorTransformer, FormContextType, RJSFSchema, RJSFValidationError, StrictRJSFSchema, UiSchema, ValidatorType } from '@rjsf/utils';
2
+ import type { ValidationError } from 'ata-validator';
3
+ import type { SuppressDuplicateFilteringType } from './types';
4
+ export type RawValidationErrorsType<Result = any> = {
5
+ errors?: Result[];
6
+ validationError?: Error;
7
+ };
8
+ /** Filters duplicate errors from `anyOf`/`oneOf` schema paths according to
9
+ * the `suppressDuplicateFiltering` flag. Mirrors the `@rjsf/validator-ajv8`
10
+ * implementation: under any non-`'all'` setting, duplicate messages that
11
+ * share a common prefix before the `/anyOf/` or `/oneOf/` segment are
12
+ * collapsed into a single entry.
13
+ */
14
+ export declare function filterDuplicateErrors(errorList: RJSFValidationError[], suppressDuplicateFiltering?: SuppressDuplicateFilteringType): RJSFValidationError[];
15
+ /** Transforms ata-validator errors into the RJSF-internal `RJSFValidationError`
16
+ * shape. ata's error objects already use the same field names AJV does
17
+ * (`instancePath`, `keyword`, `params`, `schemaPath`, `parentSchema`,
18
+ * `message`), so the conversion is structural only.
19
+ */
20
+ export declare function transformRJSFValidationErrors<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(errors?: ValidationError[], uiSchema?: UiSchema<T, S, F>, suppressDuplicateFiltering?: SuppressDuplicateFilteringType): RJSFValidationError[];
21
+ /** Processes raw ata validation errors into the `ValidationData<T>` shape
22
+ * RJSF consumes. Mirrors the AJV-validator's `processRawValidationErrors`,
23
+ * including the optional `customValidate` and `transformErrors` hooks.
24
+ */
25
+ export default function processRawValidationErrors<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rawErrors: RawValidationErrorsType<ValidationError>, formData: T | undefined, schema: S, customValidate?: CustomValidator<T, S, F>, transformErrors?: ErrorTransformer<T, S, F>, uiSchema?: UiSchema<T, S, F>, suppressDuplicateFiltering?: SuppressDuplicateFilteringType): {
26
+ errors: RJSFValidationError[];
27
+ errorSchema: import("@rjsf/utils").ErrorSchema<T>;
28
+ };
@@ -0,0 +1,137 @@
1
+ import { ANY_OF_KEY, createErrorHandler, getDefaultFormState, getUiOptions, ONE_OF_KEY, PROPERTIES_KEY, toErrorSchema, unwrapErrorHandler, validationDataMerge, } from '@rjsf/utils';
2
+ import get from 'lodash/get';
3
+ /** Filters duplicate errors from `anyOf`/`oneOf` schema paths according to
4
+ * the `suppressDuplicateFiltering` flag. Mirrors the `@rjsf/validator-ajv8`
5
+ * implementation: under any non-`'all'` setting, duplicate messages that
6
+ * share a common prefix before the `/anyOf/` or `/oneOf/` segment are
7
+ * collapsed into a single entry.
8
+ */
9
+ export function filterDuplicateErrors(errorList, suppressDuplicateFiltering = 'none') {
10
+ if (suppressDuplicateFiltering === 'all') {
11
+ return errorList;
12
+ }
13
+ return errorList.reduce((acc, err) => {
14
+ const { message, schemaPath } = err;
15
+ const anyOfIndex = suppressDuplicateFiltering !== 'anyOf' ? schemaPath === null || schemaPath === void 0 ? void 0 : schemaPath.indexOf(`/${ANY_OF_KEY}/`) : undefined;
16
+ const oneOfIndex = suppressDuplicateFiltering !== 'oneOf' ? schemaPath === null || schemaPath === void 0 ? void 0 : schemaPath.indexOf(`/${ONE_OF_KEY}/`) : undefined;
17
+ let schemaPrefix;
18
+ if (anyOfIndex && anyOfIndex >= 0) {
19
+ schemaPrefix = schemaPath === null || schemaPath === void 0 ? void 0 : schemaPath.substring(0, anyOfIndex);
20
+ }
21
+ else if (oneOfIndex && oneOfIndex >= 0) {
22
+ schemaPrefix = schemaPath === null || schemaPath === void 0 ? void 0 : schemaPath.substring(0, oneOfIndex);
23
+ }
24
+ const dup = schemaPrefix
25
+ ? acc.find((e) => { var _a; return e.message === message && ((_a = e.schemaPath) === null || _a === void 0 ? void 0 : _a.startsWith(schemaPrefix)); })
26
+ : undefined;
27
+ if (!dup) {
28
+ acc.push(err);
29
+ }
30
+ return acc;
31
+ }, []);
32
+ }
33
+ /** Transforms ata-validator errors into the RJSF-internal `RJSFValidationError`
34
+ * shape. ata's error objects already use the same field names AJV does
35
+ * (`instancePath`, `keyword`, `params`, `schemaPath`, `parentSchema`,
36
+ * `message`), so the conversion is structural only.
37
+ */
38
+ export function transformRJSFValidationErrors(errors = [], uiSchema, suppressDuplicateFiltering) {
39
+ const errorList = errors.map((e) => {
40
+ var _a;
41
+ const { instancePath, keyword, params, schemaPath, parentSchema } = e;
42
+ let { message = '' } = e;
43
+ let property = instancePath.replace(/\//g, '.');
44
+ let stack = `${property} ${message}`.trim();
45
+ let uiTitle = '';
46
+ const p = params;
47
+ const rawPropertyNames = [
48
+ ...(((_a = p === null || p === void 0 ? void 0 : p.deps) === null || _a === void 0 ? void 0 : _a.split(', ')) || []),
49
+ p === null || p === void 0 ? void 0 : p.missingProperty,
50
+ p === null || p === void 0 ? void 0 : p.property,
51
+ ].filter((item) => Boolean(item));
52
+ if (rawPropertyNames.length > 0) {
53
+ rawPropertyNames.forEach((currentProperty) => {
54
+ const path = property ? `${property}.${currentProperty}` : currentProperty;
55
+ let uiSchemaTitle = getUiOptions(get(uiSchema, `${path.replace(/^\./, '')}`)).title;
56
+ if (uiSchemaTitle === undefined) {
57
+ const uiSchemaPath = schemaPath
58
+ .replace(/\/properties\//g, '/')
59
+ .split('/')
60
+ .slice(1, -1)
61
+ .concat([currentProperty]);
62
+ uiSchemaTitle = getUiOptions(get(uiSchema, uiSchemaPath)).title;
63
+ }
64
+ if (uiSchemaTitle) {
65
+ message = message.replace(`'${currentProperty}'`, `'${uiSchemaTitle}'`);
66
+ uiTitle = uiSchemaTitle;
67
+ }
68
+ else {
69
+ const parentSchemaTitle = get(parentSchema, [PROPERTIES_KEY, currentProperty, 'title']);
70
+ if (parentSchemaTitle) {
71
+ message = message.replace(`'${currentProperty}'`, `'${parentSchemaTitle}'`);
72
+ uiTitle = parentSchemaTitle;
73
+ }
74
+ }
75
+ });
76
+ stack = message;
77
+ }
78
+ else {
79
+ const uiSchemaTitle = getUiOptions(get(uiSchema, `${property.replace(/^\./, '')}`)).title;
80
+ if (uiSchemaTitle) {
81
+ stack = `'${uiSchemaTitle}' ${message}`.trim();
82
+ uiTitle = uiSchemaTitle;
83
+ }
84
+ else {
85
+ const parentSchemaTitle = parentSchema === null || parentSchema === void 0 ? void 0 : parentSchema.title;
86
+ if (parentSchemaTitle) {
87
+ stack = `'${parentSchemaTitle}' ${message}`.trim();
88
+ uiTitle = parentSchemaTitle;
89
+ }
90
+ }
91
+ }
92
+ if (p && 'missingProperty' in p) {
93
+ property = property ? `${property}.${p.missingProperty}` : p.missingProperty;
94
+ }
95
+ return {
96
+ name: keyword,
97
+ property,
98
+ message,
99
+ params,
100
+ stack,
101
+ schemaPath,
102
+ title: uiTitle,
103
+ };
104
+ });
105
+ return filterDuplicateErrors(errorList, suppressDuplicateFiltering);
106
+ }
107
+ /** Processes raw ata validation errors into the `ValidationData<T>` shape
108
+ * RJSF consumes. Mirrors the AJV-validator's `processRawValidationErrors`,
109
+ * including the optional `customValidate` and `transformErrors` hooks.
110
+ */
111
+ export default function processRawValidationErrors(validator, rawErrors, formData, schema, customValidate, transformErrors, uiSchema, suppressDuplicateFiltering) {
112
+ const { validationError: invalidSchemaError } = rawErrors;
113
+ let errors = transformRJSFValidationErrors(rawErrors.errors, uiSchema, suppressDuplicateFiltering);
114
+ if (invalidSchemaError) {
115
+ errors = [...errors, { stack: invalidSchemaError.message }];
116
+ }
117
+ if (typeof transformErrors === 'function') {
118
+ errors = transformErrors(errors, uiSchema);
119
+ }
120
+ let errorSchema = toErrorSchema(errors);
121
+ if (invalidSchemaError) {
122
+ errorSchema = {
123
+ ...errorSchema,
124
+ $schema: {
125
+ __errors: [invalidSchemaError.message],
126
+ },
127
+ };
128
+ }
129
+ if (typeof customValidate !== 'function') {
130
+ return { errors, errorSchema };
131
+ }
132
+ const newFormData = getDefaultFormState(validator, schema, formData, schema, true);
133
+ const errorHandler = customValidate(newFormData, createErrorHandler(newFormData), uiSchema, errorSchema);
134
+ const userErrorSchema = unwrapErrorHandler(errorHandler);
135
+ return validationDataMerge({ errors, errorSchema }, userErrorSchema);
136
+ }
137
+ //# sourceMappingURL=processRawValidationErrors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processRawValidationErrors.js","sourceRoot":"","sources":["../src/processRawValidationErrors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,kBAAkB,EAIlB,mBAAmB,EACnB,YAAY,EACZ,UAAU,EACV,cAAc,EAId,aAAa,EAEb,kBAAkB,EAClB,mBAAmB,GAEpB,MAAM,aAAa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