@rjsf/validator-ajv8 6.6.0 → 6.6.2

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 (41) hide show
  1. package/dist/compileSchemaValidators.cjs.map +2 -2
  2. package/dist/compileSchemaValidators.esm.js.map +2 -2
  3. package/dist/index.cjs +2 -2
  4. package/dist/index.cjs.map +2 -2
  5. package/dist/validator-ajv8.esm.js +4 -16
  6. package/dist/validator-ajv8.esm.js.map +2 -2
  7. package/dist/validator-ajv8.umd.js +2 -2
  8. package/lib/compileSchemaValidators.d.ts +2 -2
  9. package/lib/compileSchemaValidators.js +2 -0
  10. package/lib/compileSchemaValidators.js.map +1 -1
  11. package/lib/compileSchemaValidatorsCode.d.ts +2 -2
  12. package/lib/compileSchemaValidatorsCode.js.map +1 -1
  13. package/lib/createAjvInstance.d.ts +4 -3
  14. package/lib/createAjvInstance.js.map +1 -1
  15. package/lib/createPrecompiledValidator.d.ts +2 -2
  16. package/lib/customizeValidator.d.ts +2 -2
  17. package/lib/index.d.ts +1 -1
  18. package/lib/index.js +0 -1
  19. package/lib/index.js.map +1 -1
  20. package/lib/precompiledValidator.d.ts +3 -3
  21. package/lib/precompiledValidator.js +1 -1
  22. package/lib/precompiledValidator.js.map +1 -1
  23. package/lib/processRawValidationErrors.d.ts +5 -5
  24. package/lib/processRawValidationErrors.js +2 -2
  25. package/lib/processRawValidationErrors.js.map +1 -1
  26. package/lib/tsconfig.tsbuildinfo +1 -1
  27. package/lib/types.d.ts +6 -9
  28. package/lib/validator.d.ts +4 -4
  29. package/lib/validator.js +6 -1
  30. package/lib/validator.js.map +1 -1
  31. package/package.json +3 -3
  32. package/src/compileSchemaValidators.ts +4 -2
  33. package/src/compileSchemaValidatorsCode.ts +3 -2
  34. package/src/createAjvInstance.ts +5 -3
  35. package/src/createPrecompiledValidator.ts +2 -2
  36. package/src/customizeValidator.ts +2 -2
  37. package/src/index.ts +1 -1
  38. package/src/precompiledValidator.ts +6 -9
  39. package/src/processRawValidationErrors.ts +20 -18
  40. package/src/types.ts +6 -7
  41. package/src/validator.ts +13 -10
@@ -1,7 +1,7 @@
1
- import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '@rjsf/utils';
1
+ import type { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '@rjsf/utils';
2
2
 
3
3
  import AJV8PrecompiledValidator from './precompiledValidator';
4
- import { Localizer, SuppressDuplicateFilteringType, ValidatorFunctions } from './types';
4
+ import type { Localizer, SuppressDuplicateFilteringType, ValidatorFunctions } from './types';
5
5
 
6
6
  /** Creates and returns a `ValidatorType` interface that is implemented with a precompiled validator. If a `localizer`
7
7
  * is provided, it is used to translate the messages generated by the underlying AJV validation.
@@ -1,6 +1,6 @@
1
- import { FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
1
+ import type { FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
2
2
 
3
- import { CustomValidatorOptionsType, Localizer } from './types';
3
+ import type { CustomValidatorOptionsType, Localizer } from './types';
4
4
  import AJV8Validator from './validator';
5
5
 
6
6
  /** Creates and returns a customized implementation of the `ValidatorType` with the given customization `options` if
package/src/index.ts CHANGED
@@ -2,6 +2,6 @@ import createPrecompiledValidator from './createPrecompiledValidator';
2
2
  import customizeValidator from './customizeValidator';
3
3
 
4
4
  export { customizeValidator, createPrecompiledValidator };
5
- export * from './types';
5
+ export type * from './types';
6
6
 
7
7
  export default customizeValidator();
@@ -1,23 +1,20 @@
1
- import {
1
+ import type {
2
2
  CustomValidator,
3
- deepEquals,
4
3
  ErrorTransformer,
5
4
  FormContextType,
6
- hashForSchema,
7
- ID_KEY,
8
- JUNK_OPTION_ID,
9
- retrieveSchema,
10
5
  RJSFSchema,
11
6
  StrictRJSFSchema,
12
7
  UiSchema,
13
8
  ValidationData,
14
9
  ValidatorType,
15
10
  } from '@rjsf/utils';
16
- import { ErrorObject } from 'ajv';
11
+ import { deepEquals, hashForSchema, ID_KEY, JUNK_OPTION_ID, retrieveSchema } from '@rjsf/utils';
12
+ import type { ErrorObject } from 'ajv';
17
13
  import get from 'lodash/get';
18
14
 
19
- import processRawValidationErrors, { RawValidationErrorsType } from './processRawValidationErrors';
20
- import { CompiledValidateFunction, Localizer, SuppressDuplicateFilteringType, ValidatorFunctions } from './types';
15
+ import type { RawValidationErrorsType } from './processRawValidationErrors';
16
+ import processRawValidationErrors from './processRawValidationErrors';
17
+ import type { CompiledValidateFunction, Localizer, SuppressDuplicateFilteringType, ValidatorFunctions } from './types';
21
18
 
22
19
  /** `ValidatorType` implementation that uses an AJV 8 precompiled validator as created by the
23
20
  * `compileSchemaValidators()` function provided by the `@rjsf/validator-ajv8` library.
@@ -1,31 +1,33 @@
1
- import {
2
- ANY_OF_KEY,
3
- createErrorHandler,
1
+ import type {
4
2
  CustomValidator,
5
3
  ErrorTransformer,
6
4
  FormContextType,
5
+ RJSFSchema,
6
+ RJSFValidationError,
7
+ StrictRJSFSchema,
8
+ UiSchema,
9
+ ValidatorType,
10
+ } from '@rjsf/utils';
11
+ import {
12
+ ANY_OF_KEY,
13
+ createErrorHandler,
7
14
  getDefaultFormState,
8
15
  getUiOptions,
9
16
  ONE_OF_KEY,
10
17
  PROPERTIES_KEY,
11
- RJSFSchema,
12
- RJSFValidationError,
13
- StrictRJSFSchema,
14
18
  toErrorSchema,
15
- UiSchema,
16
19
  unwrapErrorHandler,
17
20
  validationDataMerge,
18
- ValidatorType,
19
21
  } from '@rjsf/utils';
20
- import { ErrorObject } from 'ajv';
22
+ import type { ErrorObject } from 'ajv';
21
23
  import get from 'lodash/get';
22
24
 
23
- import { SuppressDuplicateFilteringType } from './types';
25
+ import type { SuppressDuplicateFilteringType } from './types';
24
26
 
25
- export type RawValidationErrorsType<Result = any> = {
27
+ export interface RawValidationErrorsType<Result = any> {
26
28
  errors?: Result[];
27
29
  validationError?: Error;
28
- };
30
+ }
29
31
 
30
32
  /** Filters duplicate errors from `anyOf`/`oneOf` schema paths according to the `suppressDuplicateFiltering` flag.
31
33
  *
@@ -43,7 +45,7 @@ export function filterDuplicateErrors(
43
45
  if (suppressDuplicateFiltering === 'all') {
44
46
  return errorList;
45
47
  }
46
- return errorList.reduce((acc: RJSFValidationError[], err: RJSFValidationError) => {
48
+ return errorList.reduce<RJSFValidationError[]>((acc: RJSFValidationError[], err: RJSFValidationError) => {
47
49
  const { message, schemaPath } = err;
48
50
  // Compute the index only when filtering for that keyword is not suppressed.
49
51
  // 'all' is already handled above; within the reduce, only 'none', 'anyOf', and 'oneOf' are possible.
@@ -63,7 +65,7 @@ export function filterDuplicateErrors(
63
65
  acc.push(err);
64
66
  }
65
67
  return acc;
66
- }, [] as RJSFValidationError[]);
68
+ }, []);
67
69
  }
68
70
 
69
71
  /** Transforming the error output from ajv to format used by @rjsf/utils.
@@ -97,7 +99,7 @@ export function transformRJSFValidationErrors<
97
99
  if (rawPropertyNames.length > 0) {
98
100
  rawPropertyNames.forEach((currentProperty) => {
99
101
  const path = property ? `${property}.${currentProperty}` : currentProperty;
100
- let uiSchemaTitle = getUiOptions(get(uiSchema, `${path.replace(/^\./, '')}`)).title;
102
+ let uiSchemaTitle = getUiOptions(get(uiSchema, path.replace(/^\./, ''))).title;
101
103
  if (uiSchemaTitle === undefined) {
102
104
  // To retrieve a title from UI schema, construct a path to UI schema from `schemaPath` and `currentProperty`.
103
105
  // For example, when `#/properties/A/properties/B/required` and `C` are given, they are converted into `['A', 'B', 'C']`.
@@ -122,7 +124,7 @@ export function transformRJSFValidationErrors<
122
124
 
123
125
  stack = message;
124
126
  } else {
125
- const uiSchemaTitle = getUiOptions<T, S, F>(get(uiSchema, `${property.replace(/^\./, '')}`)).title;
127
+ const uiSchemaTitle = getUiOptions<T, S, F>(get(uiSchema, property.replace(/^\./, ''))).title;
126
128
 
127
129
  if (uiSchemaTitle) {
128
130
  stack = `'${uiSchemaTitle}' ${message}`.trim();
@@ -188,7 +190,7 @@ export default function processRawValidationErrors<
188
190
  let errors = transformRJSFValidationErrors<T, S, F>(rawErrors.errors, uiSchema, suppressDuplicateFiltering);
189
191
 
190
192
  if (invalidSchemaError) {
191
- errors = [...errors, { stack: invalidSchemaError!.message }];
193
+ errors = [...errors, { stack: invalidSchemaError.message }];
192
194
  }
193
195
  if (typeof transformErrors === 'function') {
194
196
  errors = transformErrors(errors, uiSchema);
@@ -200,7 +202,7 @@ export default function processRawValidationErrors<
200
202
  errorSchema = {
201
203
  ...errorSchema,
202
204
  $schema: {
203
- __errors: [invalidSchemaError!.message],
205
+ __errors: [invalidSchemaError.message],
204
206
  },
205
207
  };
206
208
  }
package/src/types.ts CHANGED
@@ -1,5 +1,6 @@
1
- import Ajv, { Options, ErrorObject } from 'ajv';
2
- import { FormatsPluginOptions } from 'ajv-formats';
1
+ import type { Options, ErrorObject } from 'ajv';
2
+ import type Ajv from 'ajv';
3
+ import type { FormatsPluginOptions } from 'ajv-formats';
3
4
 
4
5
  /** The type describing the value for the `suppressDuplicateFiltering` option */
5
6
  export type SuppressDuplicateFilteringType = 'anyOf' | 'oneOf' | 'all' | 'none';
@@ -8,11 +9,9 @@ export type SuppressDuplicateFilteringType = 'anyOf' | 'oneOf' | 'all' | 'none';
8
9
  */
9
10
  export interface CustomValidatorOptionsType {
10
11
  /** The list of additional meta schemas that the validator can access */
11
- additionalMetaSchemas?: ReadonlyArray<object>;
12
+ additionalMetaSchemas?: readonly object[];
12
13
  /** The set of additional custom formats that the validator will support */
13
- customFormats?: {
14
- [k: string]: string | RegExp | ((data: string) => boolean);
15
- };
14
+ customFormats?: Record<string, string | RegExp | ((data: string) => boolean)>;
16
15
  /** The set of config overrides that will be passed to the AJV validator constructor on top of the defaults */
17
16
  ajvOptionsOverrides?: Options;
18
17
  /** The `ajv-format` options to use when adding formats to `ajv`; pass `false` to disable it */
@@ -49,4 +48,4 @@ export interface CompiledValidateFunction {
49
48
 
50
49
  /** The definition of precompiled validator functions
51
50
  */
52
- export type ValidatorFunctions = { [key: string]: CompiledValidateFunction };
51
+ export type ValidatorFunctions = Record<string, CompiledValidateFunction>;
package/src/validator.ts CHANGED
@@ -1,23 +1,21 @@
1
- import {
1
+ import type {
2
2
  CustomValidator,
3
- deepEquals,
4
3
  ErrorTransformer,
5
4
  FormContextType,
6
- ID_KEY,
7
5
  RJSFSchema,
8
- ROOT_SCHEMA_PREFIX,
9
6
  StrictRJSFSchema,
10
7
  UiSchema,
11
8
  ValidationData,
12
9
  ValidatorType,
13
- withIdRefPrefix,
14
- hashForSchema,
15
10
  } from '@rjsf/utils';
16
- import Ajv, { ErrorObject, ValidateFunction } from 'ajv';
11
+ import { deepEquals, ID_KEY, ROOT_SCHEMA_PREFIX, withIdRefPrefix, hashForSchema } from '@rjsf/utils';
12
+ import type { ErrorObject, ValidateFunction } from 'ajv';
13
+ import type Ajv from 'ajv';
17
14
 
18
15
  import createAjvInstance from './createAjvInstance';
19
- import processRawValidationErrors, { RawValidationErrorsType } from './processRawValidationErrors';
20
- import { CustomValidatorOptionsType, Localizer, SuppressDuplicateFilteringType } from './types';
16
+ import type { RawValidationErrorsType } from './processRawValidationErrors';
17
+ import processRawValidationErrors from './processRawValidationErrors';
18
+ import type { CustomValidatorOptionsType, Localizer, SuppressDuplicateFilteringType } from './types';
21
19
 
22
20
  /** `ValidatorType` implementation that uses the AJV 8 validation mechanism.
23
21
  */
@@ -121,12 +119,14 @@ export default class AJV8Validator<
121
119
  (compiledValidator.errors ?? []).forEach((error) => {
122
120
  ['missingProperty', 'property'].forEach((key) => {
123
121
  if (error.params?.[key]) {
122
+ // oxlint-disable-next-line no-param-reassign
124
123
  error.params[key] = `'${error.params[key]}'`;
125
124
  }
126
125
  });
127
126
  if (error.params?.deps) {
128
127
  // As `error.params.deps` is the comma+space separated list of missing dependencies, enclose each dependency separately.
129
128
  // For example, `A, B` is converted into `'A', 'B'`.
129
+ // oxlint-disable-next-line no-param-reassign
130
130
  error.params.deps = error.params.deps
131
131
  .split(', ')
132
132
  .map((v: string) => `'${v}'`)
@@ -138,11 +138,13 @@ export default class AJV8Validator<
138
138
  (compiledValidator.errors ?? []).forEach((error) => {
139
139
  ['missingProperty', 'property'].forEach((key) => {
140
140
  if (error.params?.[key]) {
141
+ // oxlint-disable-next-line no-param-reassign
141
142
  error.params[key] = error.params[key].slice(1, -1);
142
143
  }
143
144
  });
144
145
  if (error.params?.deps) {
145
146
  // Remove surrounding quotes from each missing dependency. For example, `'A', 'B'` is reverted to `A, B`.
147
+ // oxlint-disable-next-line no-param-reassign
146
148
  error.params.deps = error.params.deps
147
149
  .split(', ')
148
150
  .map((v: string) => v.slice(1, -1))
@@ -244,8 +246,9 @@ export default class AJV8Validator<
244
246
  this.ajv.compile(schemaWithIdRefPrefix);
245
247
  }
246
248
  const result = compiledValidator(formData);
247
- return result as boolean;
249
+ return result;
248
250
  } catch (e) {
251
+ // oxlint-disable-next-line no-console
249
252
  console.warn('Error encountered compiling schema:', e);
250
253
  return false;
251
254
  }