@rjsf/validator-ajv8 5.13.0 → 5.13.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.
- package/dist/index.js +24 -16
- package/dist/index.js.map +2 -2
- package/dist/validator-ajv8.esm.js +24 -16
- package/dist/validator-ajv8.esm.js.map +2 -2
- package/dist/validator-ajv8.umd.js +24 -16
- package/lib/precompiledValidator.d.ts +11 -2
- package/lib/precompiledValidator.js +22 -9
- package/lib/precompiledValidator.js.map +1 -1
- package/lib/validator.js +4 -3
- package/lib/validator.js.map +1 -1
- package/package.json +14 -14
- package/src/precompiledValidator.ts +25 -13
- package/src/validator.ts +4 -3
package/dist/index.js
CHANGED
|
@@ -226,9 +226,7 @@ var AJV8Validator = class {
|
|
|
226
226
|
isValid(schema, formData, rootSchema) {
|
|
227
227
|
const rootSchemaId = rootSchema[import_utils3.ID_KEY] ?? import_utils3.ROOT_SCHEMA_PREFIX;
|
|
228
228
|
try {
|
|
229
|
-
|
|
230
|
-
this.ajv.addSchema(rootSchema, rootSchemaId);
|
|
231
|
-
}
|
|
229
|
+
this.ajv.addSchema(rootSchema, rootSchemaId);
|
|
232
230
|
const schemaWithIdRefPrefix = (0, import_utils3.withIdRefPrefix)(schema);
|
|
233
231
|
const schemaId = schemaWithIdRefPrefix[import_utils3.ID_KEY] ?? (0, import_utils3.hashForSchema)(schemaWithIdRefPrefix);
|
|
234
232
|
let compiledValidator;
|
|
@@ -284,6 +282,25 @@ var AJV8PrecompiledValidator = class {
|
|
|
284
282
|
}
|
|
285
283
|
return validator;
|
|
286
284
|
}
|
|
285
|
+
/** Ensures that the validator is using the same schema as the root schema used to construct the precompiled
|
|
286
|
+
* validator. It first compares the given `schema` against the root schema and if they aren't the same, then it
|
|
287
|
+
* checks against the resolved root schema, on the chance that a resolved version of the root schema was passed in
|
|
288
|
+
* instead of the raw root schema.
|
|
289
|
+
*
|
|
290
|
+
* @param schema - The schema against which to validate the form data
|
|
291
|
+
* @param [formData] - The form data to validate if any
|
|
292
|
+
*/
|
|
293
|
+
ensureSameRootSchema(schema, formData) {
|
|
294
|
+
if (!(0, import_isEqual.default)(schema, this.rootSchema)) {
|
|
295
|
+
const resolvedRootSchema = (0, import_utils4.retrieveSchema)(this, this.rootSchema, this.rootSchema, formData);
|
|
296
|
+
if (!(0, import_isEqual.default)(schema, resolvedRootSchema)) {
|
|
297
|
+
throw new Error(
|
|
298
|
+
"The schema associated with the precompiled validator differs from the rootSchema provided for validation"
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
287
304
|
/** Converts an `errorSchema` into a list of `RJSFValidationErrors`
|
|
288
305
|
*
|
|
289
306
|
* @param errorSchema - The `ErrorSchema` instance to convert
|
|
@@ -297,17 +314,12 @@ var AJV8PrecompiledValidator = class {
|
|
|
297
314
|
/** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use
|
|
298
315
|
* by the playground. Returns the `errors` from the validation
|
|
299
316
|
*
|
|
300
|
-
* @param schema - The schema against which to validate the form data
|
|
301
|
-
* @param formData - The form data to validate
|
|
317
|
+
* @param schema - The schema against which to validate the form data
|
|
318
|
+
* @param [formData] - The form data to validate, if any
|
|
302
319
|
* @throws - Error when the schema provided does not match the base schema of the precompiled validator
|
|
303
320
|
*/
|
|
304
321
|
rawValidation(schema, formData) {
|
|
305
|
-
|
|
306
|
-
if (!(0, import_isEqual.default)(schema, resolvedRootSchema)) {
|
|
307
|
-
throw new Error(
|
|
308
|
-
"The schema associated with the precompiled schema differs from the schema provided for validation"
|
|
309
|
-
);
|
|
310
|
-
}
|
|
322
|
+
this.ensureSameRootSchema(schema, formData);
|
|
311
323
|
this.mainValidator(formData);
|
|
312
324
|
if (typeof this.localizer === "function") {
|
|
313
325
|
this.localizer(this.mainValidator.errors);
|
|
@@ -342,11 +354,7 @@ var AJV8PrecompiledValidator = class {
|
|
|
342
354
|
* isn't a precompiled validator function associated with the schema
|
|
343
355
|
*/
|
|
344
356
|
isValid(schema, formData, rootSchema) {
|
|
345
|
-
|
|
346
|
-
throw new Error(
|
|
347
|
-
"The schema associated with the precompiled validator differs from the rootSchema provided for validation"
|
|
348
|
-
);
|
|
349
|
-
}
|
|
357
|
+
this.ensureSameRootSchema(rootSchema, formData);
|
|
350
358
|
if ((0, import_get2.default)(schema, import_utils4.ID_KEY) === import_utils4.JUNK_OPTION_ID) {
|
|
351
359
|
return false;
|
|
352
360
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts", "../src/validator.ts", "../src/createAjvInstance.ts", "../src/processRawValidationErrors.ts", "../src/customizeValidator.ts", "../src/precompiledValidator.ts", "../src/createPrecompiledValidator.ts"],
|
|
4
|
-
"sourcesContent": ["import customizeValidator from './customizeValidator';\nimport createPrecompiledValidator from './createPrecompiledValidator';\n\nexport { customizeValidator, createPrecompiledValidator };\nexport * from './types';\n\nexport default customizeValidator();\n", "import Ajv, { ErrorObject, ValidateFunction } from 'ajv';\nimport {\n CustomValidator,\n ErrorSchema,\n ErrorTransformer,\n FormContextType,\n ID_KEY,\n RJSFSchema,\n ROOT_SCHEMA_PREFIX,\n StrictRJSFSchema,\n toErrorList,\n UiSchema,\n ValidationData,\n ValidatorType,\n withIdRefPrefix,\n hashForSchema,\n} from '@rjsf/utils';\n\nimport { CustomValidatorOptionsType, Localizer } from './types';\nimport createAjvInstance from './createAjvInstance';\nimport processRawValidationErrors, { RawValidationErrorsType } from './processRawValidationErrors';\n\n/** `ValidatorType` implementation that uses the AJV 8 validation mechanism.\n */\nexport default class AJV8Validator<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>\n implements ValidatorType<T, S, F>\n{\n /** The AJV instance to use for all validations\n *\n * @private\n */\n private ajv: Ajv;\n\n /** The Localizer function to use for localizing Ajv errors\n *\n * @private\n */\n readonly localizer?: Localizer;\n\n /** Constructs an `AJV8Validator` instance using the `options`\n *\n * @param options - The `CustomValidatorOptionsType` options that are used to create the AJV instance\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n */\n constructor(options: CustomValidatorOptionsType, localizer?: Localizer) {\n const { additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass } = options;\n this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass);\n this.localizer = localizer;\n }\n\n /** Converts an `errorSchema` into a list of `RJSFValidationErrors`\n *\n * @param errorSchema - The `ErrorSchema` instance to convert\n * @param [fieldPath=[]] - The current field path, defaults to [] if not specified\n * @deprecated - Use the `toErrorList()` function provided by `@rjsf/utils` instead. This function will be removed in\n * the next major release.\n */\n toErrorList(errorSchema?: ErrorSchema<T>, fieldPath: string[] = []) {\n return toErrorList(errorSchema, fieldPath);\n }\n\n /** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use\n * by the playground. Returns the `errors` from the validation\n *\n * @param schema - The schema against which to validate the form data * @param schema\n * @param formData - The form data to validate\n */\n rawValidation<Result = any>(schema: S, formData?: T): RawValidationErrorsType<Result> {\n let compilationError: Error | undefined = undefined;\n let compiledValidator: ValidateFunction | undefined;\n if (schema[ID_KEY]) {\n compiledValidator = this.ajv.getSchema(schema[ID_KEY]);\n }\n try {\n if (compiledValidator === undefined) {\n compiledValidator = this.ajv.compile(schema);\n }\n compiledValidator(formData);\n } catch (err) {\n compilationError = err as Error;\n }\n\n let errors;\n if (compiledValidator) {\n if (typeof this.localizer === 'function') {\n this.localizer(compiledValidator.errors);\n }\n errors = compiledValidator.errors || undefined;\n\n // Clear errors to prevent persistent errors, see #1104\n compiledValidator.errors = null;\n }\n\n return {\n errors: errors as unknown as Result[],\n validationError: compilationError,\n };\n }\n\n /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param formData - The form data to validate\n * @param schema - The schema against which to validate the form data\n * @param [customValidate] - An optional function that is used to perform custom validation\n * @param [transformErrors] - An optional function that is used to transform errors after AJV validation\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\n validateFormData(\n formData: T | undefined,\n schema: S,\n customValidate?: CustomValidator<T, S, F>,\n transformErrors?: ErrorTransformer<T, S, F>,\n uiSchema?: UiSchema<T, S, F>\n ): ValidationData<T> {\n const rawErrors = this.rawValidation<ErrorObject>(schema, formData);\n return processRawValidationErrors(this, rawErrors, formData, schema, customValidate, transformErrors, uiSchema);\n }\n\n /** Validates data against a schema, returning true if the data is valid, or\n * false otherwise. If the schema is invalid, then this function will return\n * false.\n *\n * @param schema - The schema against which to validate the form data\n * @param formData - The form data to validate\n * @param rootSchema - The root schema used to provide $ref resolutions\n */\n isValid(schema: S, formData: T | undefined, rootSchema: S) {\n const rootSchemaId = rootSchema[ID_KEY] ?? ROOT_SCHEMA_PREFIX;\n try {\n // add the rootSchema ROOT_SCHEMA_PREFIX as id.\n // then rewrite the schema ref's to point to the rootSchema\n // this accounts for the case where schema have references to models\n // that lives in the rootSchema but not in the schema in question.\n if (this.ajv.getSchema(rootSchemaId) === undefined) {\n this.ajv.addSchema(rootSchema, rootSchemaId);\n }\n const schemaWithIdRefPrefix = withIdRefPrefix<S>(schema) as S;\n const schemaId = schemaWithIdRefPrefix[ID_KEY] ?? hashForSchema(schemaWithIdRefPrefix);\n let compiledValidator: ValidateFunction | undefined;\n compiledValidator = this.ajv.getSchema(schemaId);\n if (compiledValidator === undefined) {\n // Add schema by an explicit ID so it can be fetched later\n // Fall back to using compile if necessary\n // https://ajv.js.org/guide/managing-schemas.html#pre-adding-all-schemas-vs-adding-on-demand\n compiledValidator =\n this.ajv.addSchema(schemaWithIdRefPrefix, schemaId).getSchema(schemaId) ||\n this.ajv.compile(schemaWithIdRefPrefix);\n }\n const result = compiledValidator(formData);\n return result as boolean;\n } catch (e) {\n console.warn('Error encountered compiling schema:', e);\n return false;\n } finally {\n // TODO: A function should be called if the root schema changes so we don't have to remove and recompile the schema every run.\n // make sure we remove the rootSchema from the global ajv instance\n this.ajv.removeSchema(rootSchemaId);\n }\n }\n}\n", "import Ajv, { Options } from 'ajv';\nimport addFormats, { FormatsPluginOptions } from 'ajv-formats';\nimport isObject from 'lodash/isObject';\n\nimport { CustomValidatorOptionsType } from './types';\nimport { ADDITIONAL_PROPERTY_FLAG, RJSF_ADDITONAL_PROPERTIES_FLAG } from '@rjsf/utils';\n\nexport const AJV_CONFIG: Options = {\n allErrors: true,\n multipleOfPrecision: 8,\n strict: false,\n verbose: true,\n} as const;\nexport const COLOR_FORMAT_REGEX =\n /^(#?([0-9A-Fa-f]{3}){1,2}\\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\\(\\s*\\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\b\\s*,\\s*\\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\b\\s*,\\s*\\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\b\\s*\\))|(rgb\\(\\s*(\\d?\\d%|100%)+\\s*,\\s*(\\d?\\d%|100%)+\\s*,\\s*(\\d?\\d%|100%)+\\s*\\)))$/;\nexport const DATA_URL_FORMAT_REGEX = /^data:([a-z]+\\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;\n\n/** Creates an Ajv version 8 implementation object with standard support for the 'color` and `data-url` custom formats.\n * If `additionalMetaSchemas` are provided then the Ajv instance is modified to add each of the meta schemas in the\n * list. If `customFormats` are provided then those additional formats are added to the list of supported formats. If\n * `ajvOptionsOverrides` are provided then they are spread on top of the default `AJV_CONFIG` options when constructing\n * the `Ajv` instance. With Ajv v8, the JSON Schema formats are not provided by default, but can be plugged in. By\n * default, all formats from the `ajv-formats` library are added. To disable this capability, set the `ajvFormatOptions`\n * parameter to `false`. Additionally, you can configure the `ajv-formats` by providing a custom set of\n * [format options](https://github.com/ajv-validator/ajv-formats) to the `ajvFormatOptions` parameter.\n *\n * @param [additionalMetaSchemas] - The list of additional meta schemas that the validator can access\n * @param [customFormats] - The set of additional custom formats that the validator will support\n * @param [ajvOptionsOverrides={}] - The set of validator config override options\n * @param [ajvFormatOptions] - The `ajv-format` options to use when adding formats to `ajv`; pass `false` to disable it\n * @param [AjvClass] - The `Ajv` class to use when creating the validator instance\n */\nexport default function createAjvInstance(\n additionalMetaSchemas?: CustomValidatorOptionsType['additionalMetaSchemas'],\n customFormats?: CustomValidatorOptionsType['customFormats'],\n ajvOptionsOverrides: CustomValidatorOptionsType['ajvOptionsOverrides'] = {},\n ajvFormatOptions?: FormatsPluginOptions | false,\n AjvClass: typeof Ajv = Ajv\n) {\n const ajv = new AjvClass({ ...AJV_CONFIG, ...ajvOptionsOverrides });\n if (ajvFormatOptions) {\n addFormats(ajv, ajvFormatOptions);\n } else if (ajvFormatOptions !== false) {\n addFormats(ajv);\n }\n\n // add custom formats\n ajv.addFormat('data-url', DATA_URL_FORMAT_REGEX);\n ajv.addFormat('color', COLOR_FORMAT_REGEX);\n\n // Add RJSF-specific additional properties keywords so Ajv doesn't report errors if strict is enabled.\n ajv.addKeyword(ADDITIONAL_PROPERTY_FLAG);\n ajv.addKeyword(RJSF_ADDITONAL_PROPERTIES_FLAG);\n\n // add more schemas to validate against\n if (Array.isArray(additionalMetaSchemas)) {\n ajv.addMetaSchema(additionalMetaSchemas);\n }\n\n // add more custom formats to validate against\n if (isObject(customFormats)) {\n Object.keys(customFormats).forEach((formatName) => {\n ajv.addFormat(formatName, customFormats[formatName]);\n });\n }\n\n return ajv;\n}\n", "import { ErrorObject } from 'ajv';\nimport get from 'lodash/get';\nimport {\n createErrorHandler,\n CustomValidator,\n ErrorTransformer,\n FormContextType,\n getDefaultFormState,\n getUiOptions,\n PROPERTIES_KEY,\n RJSFSchema,\n RJSFValidationError,\n StrictRJSFSchema,\n toErrorSchema,\n UiSchema,\n unwrapErrorHandler,\n validationDataMerge,\n ValidatorType,\n} from '@rjsf/utils';\n\nexport type RawValidationErrorsType<Result = any> = { errors?: Result[]; validationError?: Error };\n\n/** Transforming the error output from ajv to format used by @rjsf/utils.\n * At some point, components should be updated to support ajv.\n *\n * @param errors - The list of AJV errors to convert to `RJSFValidationErrors`\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\nexport function transformRJSFValidationErrors<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(errors: ErrorObject[] = [], uiSchema?: UiSchema<T, S, F>): RJSFValidationError[] {\n return errors.map((e: ErrorObject) => {\n const { instancePath, keyword, params, schemaPath, parentSchema, ...rest } = e;\n let { message = '' } = rest;\n let property = instancePath.replace(/\\//g, '.');\n let stack = `${property} ${message}`.trim();\n\n if ('missingProperty' in params) {\n property = property ? `${property}.${params.missingProperty}` : params.missingProperty;\n const currentProperty: string = params.missingProperty;\n const uiSchemaTitle = getUiOptions(get(uiSchema, `${property.replace(/^\\./, '')}`)).title;\n\n if (uiSchemaTitle) {\n message = message.replace(currentProperty, uiSchemaTitle);\n } else {\n const parentSchemaTitle = get(parentSchema, [PROPERTIES_KEY, currentProperty, 'title']);\n\n if (parentSchemaTitle) {\n message = message.replace(currentProperty, parentSchemaTitle);\n }\n }\n\n stack = message;\n } else {\n const uiSchemaTitle = getUiOptions<T, S, F>(get(uiSchema, `${property.replace(/^\\./, '')}`)).title;\n\n if (uiSchemaTitle) {\n stack = `'${uiSchemaTitle}' ${message}`.trim();\n } else {\n const parentSchemaTitle = parentSchema?.title;\n\n if (parentSchemaTitle) {\n stack = `'${parentSchemaTitle}' ${message}`.trim();\n }\n }\n }\n\n // put data in expected format\n return {\n name: keyword,\n property,\n message,\n params, // specific to ajv\n stack,\n schemaPath,\n };\n });\n}\n\n/** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param validator - The `ValidatorType` implementation used for the `getDefaultFormState()` call\n * @param rawErrors - The list of raw `ErrorObject`s to process\n * @param formData - The form data to validate\n * @param schema - The schema against which to validate the form data\n * @param [customValidate] - An optional function that is used to perform custom validation\n * @param [transformErrors] - An optional function that is used to transform errors after AJV validation\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\nexport default function processRawValidationErrors<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(\n validator: ValidatorType<T, S, F>,\n rawErrors: RawValidationErrorsType<ErrorObject>,\n formData: T | undefined,\n schema: S,\n customValidate?: CustomValidator<T, S, F>,\n transformErrors?: ErrorTransformer<T, S, F>,\n uiSchema?: UiSchema<T, S, F>\n) {\n const { validationError: invalidSchemaError } = rawErrors;\n let errors = transformRJSFValidationErrors<T, S, F>(rawErrors.errors, uiSchema);\n\n if (invalidSchemaError) {\n errors = [...errors, { stack: invalidSchemaError!.message }];\n }\n if (typeof transformErrors === 'function') {\n errors = transformErrors(errors, uiSchema);\n }\n\n let errorSchema = toErrorSchema<T>(errors);\n\n if (invalidSchemaError) {\n errorSchema = {\n ...errorSchema,\n $schema: {\n __errors: [invalidSchemaError!.message],\n },\n };\n }\n\n if (typeof customValidate !== 'function') {\n return { errors, errorSchema };\n }\n\n // Include form data with undefined values, which is required for custom validation.\n const newFormData = getDefaultFormState<T, S, F>(validator, schema, formData, schema, true) as T;\n\n const errorHandler = customValidate(newFormData, createErrorHandler<T>(newFormData), uiSchema);\n const userErrorSchema = unwrapErrorHandler<T>(errorHandler);\n return validationDataMerge<T>({ errors, errorSchema }, userErrorSchema);\n}\n", "import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '@rjsf/utils';\n\nimport { CustomValidatorOptionsType, Localizer } from './types';\nimport AJV8Validator from './validator';\n\n/** Creates and returns a customized implementation of the `ValidatorType` with the given customization `options` if\n * provided. If a `localizer` is provided, it is used to translate the messages generated by the underlying AJV\n * validation.\n *\n * @param [options={}] - The `CustomValidatorOptionsType` options that are used to create the `ValidatorType` instance\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n * @returns - The custom validator implementation resulting from the set of parameters provided\n */\nexport default function customizeValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(options: CustomValidatorOptionsType = {}, localizer?: Localizer): ValidatorType<T, S, F> {\n return new AJV8Validator<T, S, F>(options, localizer);\n}\n", "import { ErrorObject } from 'ajv';\nimport get from 'lodash/get';\nimport isEqual from 'lodash/isEqual';\nimport {\n CustomValidator,\n ErrorSchema,\n ErrorTransformer,\n FormContextType,\n hashForSchema,\n ID_KEY,\n JUNK_OPTION_ID,\n RJSFSchema,\n StrictRJSFSchema,\n toErrorList,\n UiSchema,\n ValidationData,\n ValidatorType,\n retrieveSchema,\n} from '@rjsf/utils';\n\nimport { CompiledValidateFunction, Localizer, ValidatorFunctions } from './types';\nimport processRawValidationErrors, { RawValidationErrorsType } from './processRawValidationErrors';\n\n/** `ValidatorType` implementation that uses an AJV 8 precompiled validator as created by the\n * `compileSchemaValidators()` function provided by the `@rjsf/validator-ajv8` library.\n */\nexport default class AJV8PrecompiledValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n> implements ValidatorType<T, S, F>\n{\n /** The root schema object used to construct this validator\n *\n * @private\n */\n readonly rootSchema: S;\n\n /** The `ValidatorFunctions` map used to construct this validator\n *\n * @private\n */\n readonly validateFns: ValidatorFunctions;\n\n /** The main validator function associated with the base schema in the `precompiledValidator`\n *\n * @private\n */\n readonly mainValidator: CompiledValidateFunction;\n\n /** The Localizer function to use for localizing Ajv errors\n *\n * @private\n */\n readonly localizer?: Localizer;\n\n /** Constructs an `AJV8PrecompiledValidator` instance using the `validateFns` and `rootSchema`\n *\n * @param validateFns - The map of the validation functions that are generated by the `schemaCompile()` function\n * @param rootSchema - The root schema that was used with the `compileSchema()` function\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n * @throws - Error when the base schema of the precompiled validator does not have a matching validator function\n */\n constructor(validateFns: ValidatorFunctions, rootSchema: S, localizer?: Localizer) {\n this.rootSchema = rootSchema;\n this.validateFns = validateFns;\n this.localizer = localizer;\n this.mainValidator = this.getValidator(rootSchema);\n }\n\n /** Returns the precompiled validator associated with the given `schema` from the map of precompiled validator\n * functions.\n *\n * @param schema - The schema for which a precompiled validator function is desired\n * @returns - The precompiled validator function associated with this schema\n */\n getValidator(schema: S) {\n const key = get(schema, ID_KEY) || hashForSchema(schema);\n const validator = this.validateFns[key];\n if (!validator) {\n throw new Error(`No precompiled validator function was found for the given schema for \"${key}\"`);\n }\n return validator;\n }\n\n /** Converts an `errorSchema` into a list of `RJSFValidationErrors`\n *\n * @param errorSchema - The `ErrorSchema` instance to convert\n * @param [fieldPath=[]] - The current field path, defaults to [] if not specified\n * @deprecated - Use the `toErrorList()` function provided by `@rjsf/utils` instead. This function will be removed in\n * the next major release.\n */\n toErrorList(errorSchema?: ErrorSchema<T>, fieldPath: string[] = []) {\n return toErrorList(errorSchema, fieldPath);\n }\n\n /** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use\n * by the playground. Returns the `errors` from the validation\n *\n * @param schema - The schema against which to validate the form data * @param schema\n * @param formData - The form data to validate\n * @throws - Error when the schema provided does not match the base schema of the precompiled validator\n */\n rawValidation<Result = any>(schema: S, formData?: T): RawValidationErrorsType<Result> {\n const resolvedRootSchema = retrieveSchema(this, this.rootSchema, this.rootSchema, formData);\n if (!isEqual(schema, resolvedRootSchema)) {\n throw new Error(\n 'The schema associated with the precompiled schema differs from the schema provided for validation'\n );\n }\n this.mainValidator(formData);\n\n if (typeof this.localizer === 'function') {\n this.localizer(this.mainValidator.errors);\n }\n const errors = this.mainValidator.errors || undefined;\n\n // Clear errors to prevent persistent errors, see #1104\n this.mainValidator.errors = null;\n\n return { errors: errors as unknown as Result[] };\n }\n\n /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param formData - The form data to validate\n * @param schema - The schema against which to validate the form data\n * @param [customValidate] - An optional function that is used to perform custom validation\n * @param [transformErrors] - An optional function that is used to transform errors after AJV validation\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\n validateFormData(\n formData: T | undefined,\n schema: S,\n customValidate?: CustomValidator<T, S, F>,\n transformErrors?: ErrorTransformer<T, S, F>,\n uiSchema?: UiSchema<T, S, F>\n ): ValidationData<T> {\n const rawErrors = this.rawValidation<ErrorObject>(schema, formData);\n return processRawValidationErrors(this, rawErrors, formData, schema, customValidate, transformErrors, uiSchema);\n }\n\n /** Validates data against a schema, returning true if the data is valid, or false otherwise. If the schema is\n * invalid, then this function will return false.\n *\n * @param schema - The schema against which to validate the form data\n * @param formData - The form data to validate\n * @param rootSchema - The root schema used to provide $ref resolutions\n * @returns - true if the formData validates against the schema, false otherwise\n * @throws - Error when the schema provided does not match the base schema of the precompiled validator OR if there\n * isn't a precompiled validator function associated with the schema\n */\n isValid(schema: S, formData: T | undefined, rootSchema: S) {\n if (!isEqual(rootSchema, this.rootSchema)) {\n throw new Error(\n 'The schema associated with the precompiled validator differs from the rootSchema provided for validation'\n );\n }\n if (get(schema, ID_KEY) === JUNK_OPTION_ID) {\n return false;\n }\n const validator = this.getValidator(schema);\n return validator(formData);\n }\n}\n", "import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '@rjsf/utils';\n\nimport { Localizer, ValidatorFunctions } from './types';\nimport AJV8PrecompiledValidator from './precompiledValidator';\n\n/** Creates and returns a `ValidatorType` interface that is implemented with a precompiled validator. If a `localizer`\n * is provided, it is used to translate the messages generated by the underlying AJV validation.\n *\n * NOTE: The `validateFns` parameter is an object obtained by importing from a precompiled validation file created via\n * the `compileSchemaValidators()` function.\n *\n * @param validateFns - The map of the validation functions that are created by the `compileSchemaValidators()` function\n * @param rootSchema - The root schema that was used with the `compileSchemaValidators()` function\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n * @returns - The precompiled validator implementation resulting from the set of parameters provided\n */\nexport default function createPrecompiledValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(validateFns: ValidatorFunctions, rootSchema: S, localizer?: Localizer): ValidatorType<T, S, F> {\n return new AJV8PrecompiledValidator<T, S, F>(validateFns, rootSchema, localizer);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,IAAAA,gBAeO;;;AChBP,iBAA6B;AAC7B,yBAAiD;AACjD,sBAAqB;AAGrB,mBAAyE;AAElE,IAAM,aAAsB;AAAA,EACjC,WAAW;AAAA,EACX,qBAAqB;AAAA,EACrB,QAAQ;AAAA,EACR,SAAS;AACX;AACO,IAAM,qBACX;AACK,IAAM,wBAAwB;AAiBtB,SAAR,kBACL,uBACA,eACA,sBAAyE,CAAC,GAC1E,kBACA,WAAuB,WAAAC,SACvB;AACA,QAAM,MAAM,IAAI,SAAS,EAAE,GAAG,YAAY,GAAG,oBAAoB,CAAC;AAClE,MAAI,kBAAkB;AACpB,2BAAAC,SAAW,KAAK,gBAAgB;AAAA,EAClC,WAAW,qBAAqB,OAAO;AACrC,2BAAAA,SAAW,GAAG;AAAA,EAChB;AAGA,MAAI,UAAU,YAAY,qBAAqB;AAC/C,MAAI,UAAU,SAAS,kBAAkB;AAGzC,MAAI,WAAW,qCAAwB;AACvC,MAAI,WAAW,2CAA8B;AAG7C,MAAI,MA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port createPrecompiledValidator from './createPrecompiledValidator';\n\nexport { customizeValidator, createPrecompiledValidator };\nexport * from './types';\n\nexport default customizeValidator();\n", "import Ajv, { ErrorObject, ValidateFunction } from 'ajv';\nimport {\n CustomValidator,\n ErrorSchema,\n ErrorTransformer,\n FormContextType,\n ID_KEY,\n RJSFSchema,\n ROOT_SCHEMA_PREFIX,\n StrictRJSFSchema,\n toErrorList,\n UiSchema,\n ValidationData,\n ValidatorType,\n withIdRefPrefix,\n hashForSchema,\n} from '@rjsf/utils';\n\nimport { CustomValidatorOptionsType, Localizer } from './types';\nimport createAjvInstance from './createAjvInstance';\nimport processRawValidationErrors, { RawValidationErrorsType } from './processRawValidationErrors';\n\n/** `ValidatorType` implementation that uses the AJV 8 validation mechanism.\n */\nexport default class AJV8Validator<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>\n implements ValidatorType<T, S, F>\n{\n /** The AJV instance to use for all validations\n *\n * @private\n */\n private ajv: Ajv;\n\n /** The Localizer function to use for localizing Ajv errors\n *\n * @private\n */\n readonly localizer?: Localizer;\n\n /** Constructs an `AJV8Validator` instance using the `options`\n *\n * @param options - The `CustomValidatorOptionsType` options that are used to create the AJV instance\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n */\n constructor(options: CustomValidatorOptionsType, localizer?: Localizer) {\n const { additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass } = options;\n this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass);\n this.localizer = localizer;\n }\n\n /** Converts an `errorSchema` into a list of `RJSFValidationErrors`\n *\n * @param errorSchema - The `ErrorSchema` instance to convert\n * @param [fieldPath=[]] - The current field path, defaults to [] if not specified\n * @deprecated - Use the `toErrorList()` function provided by `@rjsf/utils` instead. This function will be removed in\n * the next major release.\n */\n toErrorList(errorSchema?: ErrorSchema<T>, fieldPath: string[] = []) {\n return toErrorList(errorSchema, fieldPath);\n }\n\n /** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use\n * by the playground. Returns the `errors` from the validation\n *\n * @param schema - The schema against which to validate the form data * @param schema\n * @param formData - The form data to validate\n */\n rawValidation<Result = any>(schema: S, formData?: T): RawValidationErrorsType<Result> {\n let compilationError: Error | undefined = undefined;\n let compiledValidator: ValidateFunction | undefined;\n if (schema[ID_KEY]) {\n compiledValidator = this.ajv.getSchema(schema[ID_KEY]);\n }\n try {\n if (compiledValidator === undefined) {\n compiledValidator = this.ajv.compile(schema);\n }\n compiledValidator(formData);\n } catch (err) {\n compilationError = err as Error;\n }\n\n let errors;\n if (compiledValidator) {\n if (typeof this.localizer === 'function') {\n this.localizer(compiledValidator.errors);\n }\n errors = compiledValidator.errors || undefined;\n\n // Clear errors to prevent persistent errors, see #1104\n compiledValidator.errors = null;\n }\n\n return {\n errors: errors as unknown as Result[],\n validationError: compilationError,\n };\n }\n\n /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param formData - The form data to validate\n * @param schema - The schema against which to validate the form data\n * @param [customValidate] - An optional function that is used to perform custom validation\n * @param [transformErrors] - An optional function that is used to transform errors after AJV validation\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\n validateFormData(\n formData: T | undefined,\n schema: S,\n customValidate?: CustomValidator<T, S, F>,\n transformErrors?: ErrorTransformer<T, S, F>,\n uiSchema?: UiSchema<T, S, F>\n ): ValidationData<T> {\n const rawErrors = this.rawValidation<ErrorObject>(schema, formData);\n return processRawValidationErrors(this, rawErrors, formData, schema, customValidate, transformErrors, uiSchema);\n }\n\n /** Validates data against a schema, returning true if the data is valid, or\n * false otherwise. If the schema is invalid, then this function will return\n * false.\n *\n * @param schema - The schema against which to validate the form data\n * @param formData - The form data to validate\n * @param rootSchema - The root schema used to provide $ref resolutions\n */\n isValid(schema: S, formData: T | undefined, rootSchema: S) {\n const rootSchemaId = rootSchema[ID_KEY] ?? ROOT_SCHEMA_PREFIX;\n try {\n // add the rootSchema ROOT_SCHEMA_PREFIX as id.\n // then rewrite the schema ref's to point to the rootSchema\n // this accounts for the case where schema have references to models\n // that lives in the rootSchema but not in the schema in question.\n // if (this.ajv.getSchema(rootSchemaId) === undefined) {\n // TODO restore the commented out `if` above when the TODO in the `finally` is completed\n this.ajv.addSchema(rootSchema, rootSchemaId);\n // }\n const schemaWithIdRefPrefix = withIdRefPrefix<S>(schema) as S;\n const schemaId = schemaWithIdRefPrefix[ID_KEY] ?? hashForSchema(schemaWithIdRefPrefix);\n let compiledValidator: ValidateFunction | undefined;\n compiledValidator = this.ajv.getSchema(schemaId);\n if (compiledValidator === undefined) {\n // Add schema by an explicit ID so it can be fetched later\n // Fall back to using compile if necessary\n // https://ajv.js.org/guide/managing-schemas.html#pre-adding-all-schemas-vs-adding-on-demand\n compiledValidator =\n this.ajv.addSchema(schemaWithIdRefPrefix, schemaId).getSchema(schemaId) ||\n this.ajv.compile(schemaWithIdRefPrefix);\n }\n const result = compiledValidator(formData);\n return result as boolean;\n } catch (e) {\n console.warn('Error encountered compiling schema:', e);\n return false;\n } finally {\n // TODO: A function should be called if the root schema changes so we don't have to remove and recompile the schema every run.\n // make sure we remove the rootSchema from the global ajv instance\n this.ajv.removeSchema(rootSchemaId);\n }\n }\n}\n", "import Ajv, { Options } from 'ajv';\nimport addFormats, { FormatsPluginOptions } from 'ajv-formats';\nimport isObject from 'lodash/isObject';\n\nimport { CustomValidatorOptionsType } from './types';\nimport { ADDITIONAL_PROPERTY_FLAG, RJSF_ADDITONAL_PROPERTIES_FLAG } from '@rjsf/utils';\n\nexport const AJV_CONFIG: Options = {\n allErrors: true,\n multipleOfPrecision: 8,\n strict: false,\n verbose: true,\n} as const;\nexport const COLOR_FORMAT_REGEX =\n /^(#?([0-9A-Fa-f]{3}){1,2}\\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\\(\\s*\\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\b\\s*,\\s*\\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\b\\s*,\\s*\\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\b\\s*\\))|(rgb\\(\\s*(\\d?\\d%|100%)+\\s*,\\s*(\\d?\\d%|100%)+\\s*,\\s*(\\d?\\d%|100%)+\\s*\\)))$/;\nexport const DATA_URL_FORMAT_REGEX = /^data:([a-z]+\\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;\n\n/** Creates an Ajv version 8 implementation object with standard support for the 'color` and `data-url` custom formats.\n * If `additionalMetaSchemas` are provided then the Ajv instance is modified to add each of the meta schemas in the\n * list. If `customFormats` are provided then those additional formats are added to the list of supported formats. If\n * `ajvOptionsOverrides` are provided then they are spread on top of the default `AJV_CONFIG` options when constructing\n * the `Ajv` instance. With Ajv v8, the JSON Schema formats are not provided by default, but can be plugged in. By\n * default, all formats from the `ajv-formats` library are added. To disable this capability, set the `ajvFormatOptions`\n * parameter to `false`. Additionally, you can configure the `ajv-formats` by providing a custom set of\n * [format options](https://github.com/ajv-validator/ajv-formats) to the `ajvFormatOptions` parameter.\n *\n * @param [additionalMetaSchemas] - The list of additional meta schemas that the validator can access\n * @param [customFormats] - The set of additional custom formats that the validator will support\n * @param [ajvOptionsOverrides={}] - The set of validator config override options\n * @param [ajvFormatOptions] - The `ajv-format` options to use when adding formats to `ajv`; pass `false` to disable it\n * @param [AjvClass] - The `Ajv` class to use when creating the validator instance\n */\nexport default function createAjvInstance(\n additionalMetaSchemas?: CustomValidatorOptionsType['additionalMetaSchemas'],\n customFormats?: CustomValidatorOptionsType['customFormats'],\n ajvOptionsOverrides: CustomValidatorOptionsType['ajvOptionsOverrides'] = {},\n ajvFormatOptions?: FormatsPluginOptions | false,\n AjvClass: typeof Ajv = Ajv\n) {\n const ajv = new AjvClass({ ...AJV_CONFIG, ...ajvOptionsOverrides });\n if (ajvFormatOptions) {\n addFormats(ajv, ajvFormatOptions);\n } else if (ajvFormatOptions !== false) {\n addFormats(ajv);\n }\n\n // add custom formats\n ajv.addFormat('data-url', DATA_URL_FORMAT_REGEX);\n ajv.addFormat('color', COLOR_FORMAT_REGEX);\n\n // Add RJSF-specific additional properties keywords so Ajv doesn't report errors if strict is enabled.\n ajv.addKeyword(ADDITIONAL_PROPERTY_FLAG);\n ajv.addKeyword(RJSF_ADDITONAL_PROPERTIES_FLAG);\n\n // add more schemas to validate against\n if (Array.isArray(additionalMetaSchemas)) {\n ajv.addMetaSchema(additionalMetaSchemas);\n }\n\n // add more custom formats to validate against\n if (isObject(customFormats)) {\n Object.keys(customFormats).forEach((formatName) => {\n ajv.addFormat(formatName, customFormats[formatName]);\n });\n }\n\n return ajv;\n}\n", "import { ErrorObject } from 'ajv';\nimport get from 'lodash/get';\nimport {\n createErrorHandler,\n CustomValidator,\n ErrorTransformer,\n FormContextType,\n getDefaultFormState,\n getUiOptions,\n PROPERTIES_KEY,\n RJSFSchema,\n RJSFValidationError,\n StrictRJSFSchema,\n toErrorSchema,\n UiSchema,\n unwrapErrorHandler,\n validationDataMerge,\n ValidatorType,\n} from '@rjsf/utils';\n\nexport type RawValidationErrorsType<Result = any> = { errors?: Result[]; validationError?: Error };\n\n/** Transforming the error output from ajv to format used by @rjsf/utils.\n * At some point, components should be updated to support ajv.\n *\n * @param errors - The list of AJV errors to convert to `RJSFValidationErrors`\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\nexport function transformRJSFValidationErrors<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(errors: ErrorObject[] = [], uiSchema?: UiSchema<T, S, F>): RJSFValidationError[] {\n return errors.map((e: ErrorObject) => {\n const { instancePath, keyword, params, schemaPath, parentSchema, ...rest } = e;\n let { message = '' } = rest;\n let property = instancePath.replace(/\\//g, '.');\n let stack = `${property} ${message}`.trim();\n\n if ('missingProperty' in params) {\n property = property ? `${property}.${params.missingProperty}` : params.missingProperty;\n const currentProperty: string = params.missingProperty;\n const uiSchemaTitle = getUiOptions(get(uiSchema, `${property.replace(/^\\./, '')}`)).title;\n\n if (uiSchemaTitle) {\n message = message.replace(currentProperty, uiSchemaTitle);\n } else {\n const parentSchemaTitle = get(parentSchema, [PROPERTIES_KEY, currentProperty, 'title']);\n\n if (parentSchemaTitle) {\n message = message.replace(currentProperty, parentSchemaTitle);\n }\n }\n\n stack = message;\n } else {\n const uiSchemaTitle = getUiOptions<T, S, F>(get(uiSchema, `${property.replace(/^\\./, '')}`)).title;\n\n if (uiSchemaTitle) {\n stack = `'${uiSchemaTitle}' ${message}`.trim();\n } else {\n const parentSchemaTitle = parentSchema?.title;\n\n if (parentSchemaTitle) {\n stack = `'${parentSchemaTitle}' ${message}`.trim();\n }\n }\n }\n\n // put data in expected format\n return {\n name: keyword,\n property,\n message,\n params, // specific to ajv\n stack,\n schemaPath,\n };\n });\n}\n\n/** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param validator - The `ValidatorType` implementation used for the `getDefaultFormState()` call\n * @param rawErrors - The list of raw `ErrorObject`s to process\n * @param formData - The form data to validate\n * @param schema - The schema against which to validate the form data\n * @param [customValidate] - An optional function that is used to perform custom validation\n * @param [transformErrors] - An optional function that is used to transform errors after AJV validation\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\nexport default function processRawValidationErrors<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(\n validator: ValidatorType<T, S, F>,\n rawErrors: RawValidationErrorsType<ErrorObject>,\n formData: T | undefined,\n schema: S,\n customValidate?: CustomValidator<T, S, F>,\n transformErrors?: ErrorTransformer<T, S, F>,\n uiSchema?: UiSchema<T, S, F>\n) {\n const { validationError: invalidSchemaError } = rawErrors;\n let errors = transformRJSFValidationErrors<T, S, F>(rawErrors.errors, uiSchema);\n\n if (invalidSchemaError) {\n errors = [...errors, { stack: invalidSchemaError!.message }];\n }\n if (typeof transformErrors === 'function') {\n errors = transformErrors(errors, uiSchema);\n }\n\n let errorSchema = toErrorSchema<T>(errors);\n\n if (invalidSchemaError) {\n errorSchema = {\n ...errorSchema,\n $schema: {\n __errors: [invalidSchemaError!.message],\n },\n };\n }\n\n if (typeof customValidate !== 'function') {\n return { errors, errorSchema };\n }\n\n // Include form data with undefined values, which is required for custom validation.\n const newFormData = getDefaultFormState<T, S, F>(validator, schema, formData, schema, true) as T;\n\n const errorHandler = customValidate(newFormData, createErrorHandler<T>(newFormData), uiSchema);\n const userErrorSchema = unwrapErrorHandler<T>(errorHandler);\n return validationDataMerge<T>({ errors, errorSchema }, userErrorSchema);\n}\n", "import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '@rjsf/utils';\n\nimport { CustomValidatorOptionsType, Localizer } from './types';\nimport AJV8Validator from './validator';\n\n/** Creates and returns a customized implementation of the `ValidatorType` with the given customization `options` if\n * provided. If a `localizer` is provided, it is used to translate the messages generated by the underlying AJV\n * validation.\n *\n * @param [options={}] - The `CustomValidatorOptionsType` options that are used to create the `ValidatorType` instance\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n * @returns - The custom validator implementation resulting from the set of parameters provided\n */\nexport default function customizeValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(options: CustomValidatorOptionsType = {}, localizer?: Localizer): ValidatorType<T, S, F> {\n return new AJV8Validator<T, S, F>(options, localizer);\n}\n", "import { ErrorObject } from 'ajv';\nimport get from 'lodash/get';\nimport isEqual from 'lodash/isEqual';\nimport {\n CustomValidator,\n ErrorSchema,\n ErrorTransformer,\n FormContextType,\n hashForSchema,\n ID_KEY,\n JUNK_OPTION_ID,\n RJSFSchema,\n StrictRJSFSchema,\n toErrorList,\n UiSchema,\n ValidationData,\n ValidatorType,\n retrieveSchema,\n} from '@rjsf/utils';\n\nimport { CompiledValidateFunction, Localizer, ValidatorFunctions } from './types';\nimport processRawValidationErrors, { RawValidationErrorsType } from './processRawValidationErrors';\n\n/** `ValidatorType` implementation that uses an AJV 8 precompiled validator as created by the\n * `compileSchemaValidators()` function provided by the `@rjsf/validator-ajv8` library.\n */\nexport default class AJV8PrecompiledValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n> implements ValidatorType<T, S, F>\n{\n /** The root schema object used to construct this validator\n *\n * @private\n */\n readonly rootSchema: S;\n\n /** The `ValidatorFunctions` map used to construct this validator\n *\n * @private\n */\n readonly validateFns: ValidatorFunctions;\n\n /** The main validator function associated with the base schema in the `precompiledValidator`\n *\n * @private\n */\n readonly mainValidator: CompiledValidateFunction;\n\n /** The Localizer function to use for localizing Ajv errors\n *\n * @private\n */\n readonly localizer?: Localizer;\n\n /** Constructs an `AJV8PrecompiledValidator` instance using the `validateFns` and `rootSchema`\n *\n * @param validateFns - The map of the validation functions that are generated by the `schemaCompile()` function\n * @param rootSchema - The root schema that was used with the `compileSchema()` function\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n * @throws - Error when the base schema of the precompiled validator does not have a matching validator function\n */\n constructor(validateFns: ValidatorFunctions, rootSchema: S, localizer?: Localizer) {\n this.rootSchema = rootSchema;\n this.validateFns = validateFns;\n this.localizer = localizer;\n this.mainValidator = this.getValidator(rootSchema);\n }\n\n /** Returns the precompiled validator associated with the given `schema` from the map of precompiled validator\n * functions.\n *\n * @param schema - The schema for which a precompiled validator function is desired\n * @returns - The precompiled validator function associated with this schema\n */\n getValidator(schema: S) {\n const key = get(schema, ID_KEY) || hashForSchema(schema);\n const validator = this.validateFns[key];\n if (!validator) {\n throw new Error(`No precompiled validator function was found for the given schema for \"${key}\"`);\n }\n return validator;\n }\n\n /** Ensures that the validator is using the same schema as the root schema used to construct the precompiled\n * validator. It first compares the given `schema` against the root schema and if they aren't the same, then it\n * checks against the resolved root schema, on the chance that a resolved version of the root schema was passed in\n * instead of the raw root schema.\n *\n * @param schema - The schema against which to validate the form data\n * @param [formData] - The form data to validate if any\n */\n ensureSameRootSchema(schema: S, formData?: T) {\n if (!isEqual(schema, this.rootSchema)) {\n // Resolve the root schema with the passed in form data since that may affect the resolution\n const resolvedRootSchema = retrieveSchema(this, this.rootSchema, this.rootSchema, formData);\n if (!isEqual(schema, resolvedRootSchema)) {\n throw new Error(\n 'The schema associated with the precompiled validator differs from the rootSchema provided for validation'\n );\n }\n }\n return true;\n }\n\n /** Converts an `errorSchema` into a list of `RJSFValidationErrors`\n *\n * @param errorSchema - The `ErrorSchema` instance to convert\n * @param [fieldPath=[]] - The current field path, defaults to [] if not specified\n * @deprecated - Use the `toErrorList()` function provided by `@rjsf/utils` instead. This function will be removed in\n * the next major release.\n */\n toErrorList(errorSchema?: ErrorSchema<T>, fieldPath: string[] = []) {\n return toErrorList(errorSchema, fieldPath);\n }\n\n /** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use\n * by the playground. Returns the `errors` from the validation\n *\n * @param schema - The schema against which to validate the form data\n * @param [formData] - The form data to validate, if any\n * @throws - Error when the schema provided does not match the base schema of the precompiled validator\n */\n rawValidation<Result = any>(schema: S, formData?: T): RawValidationErrorsType<Result> {\n this.ensureSameRootSchema(schema, formData);\n this.mainValidator(formData);\n\n if (typeof this.localizer === 'function') {\n this.localizer(this.mainValidator.errors);\n }\n const errors = this.mainValidator.errors || undefined;\n\n // Clear errors to prevent persistent errors, see #1104\n this.mainValidator.errors = null;\n\n return { errors: errors as unknown as Result[] };\n }\n\n /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param formData - The form data to validate\n * @param schema - The schema against which to validate the form data\n * @param [customValidate] - An optional function that is used to perform custom validation\n * @param [transformErrors] - An optional function that is used to transform errors after AJV validation\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\n validateFormData(\n formData: T | undefined,\n schema: S,\n customValidate?: CustomValidator<T, S, F>,\n transformErrors?: ErrorTransformer<T, S, F>,\n uiSchema?: UiSchema<T, S, F>\n ): ValidationData<T> {\n const rawErrors = this.rawValidation<ErrorObject>(schema, formData);\n return processRawValidationErrors(this, rawErrors, formData, schema, customValidate, transformErrors, uiSchema);\n }\n\n /** Validates data against a schema, returning true if the data is valid, or false otherwise. If the schema is\n * invalid, then this function will return false.\n *\n * @param schema - The schema against which to validate the form data\n * @param formData - The form data to validate\n * @param rootSchema - The root schema used to provide $ref resolutions\n * @returns - true if the formData validates against the schema, false otherwise\n * @throws - Error when the schema provided does not match the base schema of the precompiled validator OR if there\n * isn't a precompiled validator function associated with the schema\n */\n isValid(schema: S, formData: T | undefined, rootSchema: S) {\n this.ensureSameRootSchema(rootSchema, formData);\n if (get(schema, ID_KEY) === JUNK_OPTION_ID) {\n return false;\n }\n const validator = this.getValidator(schema);\n return validator(formData);\n }\n}\n", "import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '@rjsf/utils';\n\nimport { Localizer, ValidatorFunctions } from './types';\nimport AJV8PrecompiledValidator from './precompiledValidator';\n\n/** Creates and returns a `ValidatorType` interface that is implemented with a precompiled validator. If a `localizer`\n * is provided, it is used to translate the messages generated by the underlying AJV validation.\n *\n * NOTE: The `validateFns` parameter is an object obtained by importing from a precompiled validation file created via\n * the `compileSchemaValidators()` function.\n *\n * @param validateFns - The map of the validation functions that are created by the `compileSchemaValidators()` function\n * @param rootSchema - The root schema that was used with the `compileSchemaValidators()` function\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n * @returns - The precompiled validator implementation resulting from the set of parameters provided\n */\nexport default function createPrecompiledValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(validateFns: ValidatorFunctions, rootSchema: S, localizer?: Localizer): ValidatorType<T, S, F> {\n return new AJV8PrecompiledValidator<T, S, F>(validateFns, rootSchema, localizer);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,IAAAA,gBAeO;;;AChBP,iBAA6B;AAC7B,yBAAiD;AACjD,sBAAqB;AAGrB,mBAAyE;AAElE,IAAM,aAAsB;AAAA,EACjC,WAAW;AAAA,EACX,qBAAqB;AAAA,EACrB,QAAQ;AAAA,EACR,SAAS;AACX;AACO,IAAM,qBACX;AACK,IAAM,wBAAwB;AAiBtB,SAAR,kBACL,uBACA,eACA,sBAAyE,CAAC,GAC1E,kBACA,WAAuB,WAAAC,SACvB;AACA,QAAM,MAAM,IAAI,SAAS,EAAE,GAAG,YAAY,GAAG,oBAAoB,CAAC;AAClE,MAAI,kBAAkB;AACpB,2BAAAC,SAAW,KAAK,gBAAgB;AAAA,EAClC,WAAW,qBAAqB,OAAO;AACrC,2BAAAA,SAAW,GAAG;AAAA,EAChB;AAGA,MAAI,UAAU,YAAY,qBAAqB;AAC/C,MAAI,UAAU,SAAS,kBAAkB;AAGzC,MAAI,WAAW,qCAAwB;AACvC,MAAI,WAAW,2CAA8B;AAG7C,MAAI,MAAM,QAAQ,qBAAqB,GAAG;AACxC,QAAI,cAAc,qBAAqB;AAAA,EACzC;AAGA,UAAI,gBAAAC,SAAS,aAAa,GAAG;AAC3B,WAAO,KAAK,aAAa,EAAE,QAAQ,CAAC,eAAe;AACjD,UAAI,UAAU,YAAY,cAAc,UAAU,CAAC;AAAA,IACrD,CAAC;AAAA,EACH;AAEA,SAAO;AACT;;;AClEA,iBAAgB;AAChB,IAAAC,g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,GAAG;AAClE,eAAO,2BAAY,aAAa,SAAS;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,cAA4B,QAAW,UAA+C;AACpF,SAAK,qBAAqB,QAAQ,QAAQ;AAC1C,SAAK,cAAc,QAAQ;AAE3B,QAAI,OAAO,KAAK,cAAc,YAAY;AACxC,WAAK,UAAU,KAAK,cAAc,MAAM;AAAA,IAC1C;AACA,UAAM,SAAS,KAAK,cAAc,UAAU;AAG5C,SAAK,cAAc,SAAS;AAE5B,WAAO,EAAE,OAAsC;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,iBACE,UACA,QACA,gBACA,iBACA,UACmB;AACnB,UAAM,YAAY,KAAK,cAA2B,QAAQ,QAAQ;AAClE,WAAO,2BAA2B,MAAM,WAAW,UAAU,QAAQ,gBAAgB,iBAAiB,QAAQ;AAAA,EAChH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,QAAQ,QAAW,UAAyB,YAAe;AACzD,SAAK,qBAAqB,YAAY,QAAQ;AAC9C,YAAI,YAAAD,SAAI,QAAQ,oBAAM,MAAM,8BAAgB;AAC1C,aAAO;AAAA,IACT;AACA,UAAM,YAAY,KAAK,aAAa,MAAM;AAC1C,WAAO,UAAU,QAAQ;AAAA,EAC3B;AACF;;;ACnKe,SAAR,2BAIL,aAAiC,YAAe,WAA+C;AAC/F,SAAO,IAAI,yBAAkC,aAAa,YAAY,SAAS;AACjF;;;ANhBA,IAAO,cAAQ,mBAAmB;",
|
|
6
6
|
"names": ["import_utils", "Ajv", "addFormats", "isObject", "import_utils", "get", "import_get", "import_utils", "get", "isEqual"]
|
|
7
7
|
}
|
|
@@ -202,9 +202,7 @@ var AJV8Validator = class {
|
|
|
202
202
|
isValid(schema, formData, rootSchema) {
|
|
203
203
|
const rootSchemaId = rootSchema[ID_KEY] ?? ROOT_SCHEMA_PREFIX;
|
|
204
204
|
try {
|
|
205
|
-
|
|
206
|
-
this.ajv.addSchema(rootSchema, rootSchemaId);
|
|
207
|
-
}
|
|
205
|
+
this.ajv.addSchema(rootSchema, rootSchemaId);
|
|
208
206
|
const schemaWithIdRefPrefix = withIdRefPrefix(schema);
|
|
209
207
|
const schemaId = schemaWithIdRefPrefix[ID_KEY] ?? hashForSchema(schemaWithIdRefPrefix);
|
|
210
208
|
let compiledValidator;
|
|
@@ -266,6 +264,25 @@ var AJV8PrecompiledValidator = class {
|
|
|
266
264
|
}
|
|
267
265
|
return validator;
|
|
268
266
|
}
|
|
267
|
+
/** Ensures that the validator is using the same schema as the root schema used to construct the precompiled
|
|
268
|
+
* validator. It first compares the given `schema` against the root schema and if they aren't the same, then it
|
|
269
|
+
* checks against the resolved root schema, on the chance that a resolved version of the root schema was passed in
|
|
270
|
+
* instead of the raw root schema.
|
|
271
|
+
*
|
|
272
|
+
* @param schema - The schema against which to validate the form data
|
|
273
|
+
* @param [formData] - The form data to validate if any
|
|
274
|
+
*/
|
|
275
|
+
ensureSameRootSchema(schema, formData) {
|
|
276
|
+
if (!isEqual(schema, this.rootSchema)) {
|
|
277
|
+
const resolvedRootSchema = retrieveSchema(this, this.rootSchema, this.rootSchema, formData);
|
|
278
|
+
if (!isEqual(schema, resolvedRootSchema)) {
|
|
279
|
+
throw new Error(
|
|
280
|
+
"The schema associated with the precompiled validator differs from the rootSchema provided for validation"
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
269
286
|
/** Converts an `errorSchema` into a list of `RJSFValidationErrors`
|
|
270
287
|
*
|
|
271
288
|
* @param errorSchema - The `ErrorSchema` instance to convert
|
|
@@ -279,17 +296,12 @@ var AJV8PrecompiledValidator = class {
|
|
|
279
296
|
/** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use
|
|
280
297
|
* by the playground. Returns the `errors` from the validation
|
|
281
298
|
*
|
|
282
|
-
* @param schema - The schema against which to validate the form data
|
|
283
|
-
* @param formData - The form data to validate
|
|
299
|
+
* @param schema - The schema against which to validate the form data
|
|
300
|
+
* @param [formData] - The form data to validate, if any
|
|
284
301
|
* @throws - Error when the schema provided does not match the base schema of the precompiled validator
|
|
285
302
|
*/
|
|
286
303
|
rawValidation(schema, formData) {
|
|
287
|
-
|
|
288
|
-
if (!isEqual(schema, resolvedRootSchema)) {
|
|
289
|
-
throw new Error(
|
|
290
|
-
"The schema associated with the precompiled schema differs from the schema provided for validation"
|
|
291
|
-
);
|
|
292
|
-
}
|
|
304
|
+
this.ensureSameRootSchema(schema, formData);
|
|
293
305
|
this.mainValidator(formData);
|
|
294
306
|
if (typeof this.localizer === "function") {
|
|
295
307
|
this.localizer(this.mainValidator.errors);
|
|
@@ -324,11 +336,7 @@ var AJV8PrecompiledValidator = class {
|
|
|
324
336
|
* isn't a precompiled validator function associated with the schema
|
|
325
337
|
*/
|
|
326
338
|
isValid(schema, formData, rootSchema) {
|
|
327
|
-
|
|
328
|
-
throw new Error(
|
|
329
|
-
"The schema associated with the precompiled validator differs from the rootSchema provided for validation"
|
|
330
|
-
);
|
|
331
|
-
}
|
|
339
|
+
this.ensureSameRootSchema(rootSchema, formData);
|
|
332
340
|
if (get2(schema, ID_KEY2) === JUNK_OPTION_ID) {
|
|
333
341
|
return false;
|
|
334
342
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/validator.ts", "../src/createAjvInstance.ts", "../src/processRawValidationErrors.ts", "../src/customizeValidator.ts", "../src/precompiledValidator.ts", "../src/createPrecompiledValidator.ts", "../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import Ajv, { ErrorObject, ValidateFunction } from 'ajv';\nimport {\n CustomValidator,\n ErrorSchema,\n ErrorTransformer,\n FormContextType,\n ID_KEY,\n RJSFSchema,\n ROOT_SCHEMA_PREFIX,\n StrictRJSFSchema,\n toErrorList,\n UiSchema,\n ValidationData,\n ValidatorType,\n withIdRefPrefix,\n hashForSchema,\n} from '@rjsf/utils';\n\nimport { CustomValidatorOptionsType, Localizer } from './types';\nimport createAjvInstance from './createAjvInstance';\nimport processRawValidationErrors, { RawValidationErrorsType } from './processRawValidationErrors';\n\n/** `ValidatorType` implementation that uses the AJV 8 validation mechanism.\n */\nexport default class AJV8Validator<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>\n implements ValidatorType<T, S, F>\n{\n /** The AJV instance to use for all validations\n *\n * @private\n */\n private ajv: Ajv;\n\n /** The Localizer function to use for localizing Ajv errors\n *\n * @private\n */\n readonly localizer?: Localizer;\n\n /** Constructs an `AJV8Validator` instance using the `options`\n *\n * @param options - The `CustomValidatorOptionsType` options that are used to create the AJV instance\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n */\n constructor(options: CustomValidatorOptionsType, localizer?: Localizer) {\n const { additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass } = options;\n this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass);\n this.localizer = localizer;\n }\n\n /** Converts an `errorSchema` into a list of `RJSFValidationErrors`\n *\n * @param errorSchema - The `ErrorSchema` instance to convert\n * @param [fieldPath=[]] - The current field path, defaults to [] if not specified\n * @deprecated - Use the `toErrorList()` function provided by `@rjsf/utils` instead. This function will be removed in\n * the next major release.\n */\n toErrorList(errorSchema?: ErrorSchema<T>, fieldPath: string[] = []) {\n return toErrorList(errorSchema, fieldPath);\n }\n\n /** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use\n * by the playground. Returns the `errors` from the validation\n *\n * @param schema - The schema against which to validate the form data * @param schema\n * @param formData - The form data to validate\n */\n rawValidation<Result = any>(schema: S, formData?: T): RawValidationErrorsType<Result> {\n let compilationError: Error | undefined = undefined;\n let compiledValidator: ValidateFunction | undefined;\n if (schema[ID_KEY]) {\n compiledValidator = this.ajv.getSchema(schema[ID_KEY]);\n }\n try {\n if (compiledValidator === undefined) {\n compiledValidator = this.ajv.compile(schema);\n }\n compiledValidator(formData);\n } catch (err) {\n compilationError = err as Error;\n }\n\n let errors;\n if (compiledValidator) {\n if (typeof this.localizer === 'function') {\n this.localizer(compiledValidator.errors);\n }\n errors = compiledValidator.errors || undefined;\n\n // Clear errors to prevent persistent errors, see #1104\n compiledValidator.errors = null;\n }\n\n return {\n errors: errors as unknown as Result[],\n validationError: compilationError,\n };\n }\n\n /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param formData - The form data to validate\n * @param schema - The schema against which to validate the form data\n * @param [customValidate] - An optional function that is used to perform custom validation\n * @param [transformErrors] - An optional function that is used to transform errors after AJV validation\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\n validateFormData(\n formData: T | undefined,\n schema: S,\n customValidate?: CustomValidator<T, S, F>,\n transformErrors?: ErrorTransformer<T, S, F>,\n uiSchema?: UiSchema<T, S, F>\n ): ValidationData<T> {\n const rawErrors = this.rawValidation<ErrorObject>(schema, formData);\n return processRawValidationErrors(this, rawErrors, formData, schema, customValidate, transformErrors, uiSchema);\n }\n\n /** Validates data against a schema, returning true if the data is valid, or\n * false otherwise. If the schema is invalid, then this function will return\n * false.\n *\n * @param schema - The schema against which to validate the form data\n * @param formData - The form data to validate\n * @param rootSchema - The root schema used to provide $ref resolutions\n */\n isValid(schema: S, formData: T | undefined, rootSchema: S) {\n const rootSchemaId = rootSchema[ID_KEY] ?? ROOT_SCHEMA_PREFIX;\n try {\n // add the rootSchema ROOT_SCHEMA_PREFIX as id.\n // then rewrite the schema ref's to point to the rootSchema\n // this accounts for the case where schema have references to models\n // that lives in the rootSchema but not in the schema in question.\n if (this.ajv.getSchema(rootSchemaId) === undefined) {\n this.ajv.addSchema(rootSchema, rootSchemaId);\n }\n const schemaWithIdRefPrefix = withIdRefPrefix<S>(schema) as S;\n const schemaId = schemaWithIdRefPrefix[ID_KEY] ?? hashForSchema(schemaWithIdRefPrefix);\n let compiledValidator: ValidateFunction | undefined;\n compiledValidator = this.ajv.getSchema(schemaId);\n if (compiledValidator === undefined) {\n // Add schema by an explicit ID so it can be fetched later\n // Fall back to using compile if necessary\n // https://ajv.js.org/guide/managing-schemas.html#pre-adding-all-schemas-vs-adding-on-demand\n compiledValidator =\n this.ajv.addSchema(schemaWithIdRefPrefix, schemaId).getSchema(schemaId) ||\n this.ajv.compile(schemaWithIdRefPrefix);\n }\n const result = compiledValidator(formData);\n return result as boolean;\n } catch (e) {\n console.warn('Error encountered compiling schema:', e);\n return false;\n } finally {\n // TODO: A function should be called if the root schema changes so we don't have to remove and recompile the schema every run.\n // make sure we remove the rootSchema from the global ajv instance\n this.ajv.removeSchema(rootSchemaId);\n }\n }\n}\n", "import Ajv, { Options } from 'ajv';\nimport addFormats, { FormatsPluginOptions } from 'ajv-formats';\nimport isObject from 'lodash/isObject';\n\nimport { CustomValidatorOptionsType } from './types';\nimport { ADDITIONAL_PROPERTY_FLAG, RJSF_ADDITONAL_PROPERTIES_FLAG } from '@rjsf/utils';\n\nexport const AJV_CONFIG: Options = {\n allErrors: true,\n multipleOfPrecision: 8,\n strict: false,\n verbose: true,\n} as const;\nexport const COLOR_FORMAT_REGEX =\n /^(#?([0-9A-Fa-f]{3}){1,2}\\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\\(\\s*\\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\b\\s*,\\s*\\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\b\\s*,\\s*\\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\b\\s*\\))|(rgb\\(\\s*(\\d?\\d%|100%)+\\s*,\\s*(\\d?\\d%|100%)+\\s*,\\s*(\\d?\\d%|100%)+\\s*\\)))$/;\nexport const DATA_URL_FORMAT_REGEX = /^data:([a-z]+\\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;\n\n/** Creates an Ajv version 8 implementation object with standard support for the 'color` and `data-url` custom formats.\n * If `additionalMetaSchemas` are provided then the Ajv instance is modified to add each of the meta schemas in the\n * list. If `customFormats` are provided then those additional formats are added to the list of supported formats. If\n * `ajvOptionsOverrides` are provided then they are spread on top of the default `AJV_CONFIG` options when constructing\n * the `Ajv` instance. With Ajv v8, the JSON Schema formats are not provided by default, but can be plugged in. By\n * default, all formats from the `ajv-formats` library are added. To disable this capability, set the `ajvFormatOptions`\n * parameter to `false`. Additionally, you can configure the `ajv-formats` by providing a custom set of\n * [format options](https://github.com/ajv-validator/ajv-formats) to the `ajvFormatOptions` parameter.\n *\n * @param [additionalMetaSchemas] - The list of additional meta schemas that the validator can access\n * @param [customFormats] - The set of additional custom formats that the validator will support\n * @param [ajvOptionsOverrides={}] - The set of validator config override options\n * @param [ajvFormatOptions] - The `ajv-format` options to use when adding formats to `ajv`; pass `false` to disable it\n * @param [AjvClass] - The `Ajv` class to use when creating the validator instance\n */\nexport default function createAjvInstance(\n additionalMetaSchemas?: CustomValidatorOptionsType['additionalMetaSchemas'],\n customFormats?: CustomValidatorOptionsType['customFormats'],\n ajvOptionsOverrides: CustomValidatorOptionsType['ajvOptionsOverrides'] = {},\n ajvFormatOptions?: FormatsPluginOptions | false,\n AjvClass: typeof Ajv = Ajv\n) {\n const ajv = new AjvClass({ ...AJV_CONFIG, ...ajvOptionsOverrides });\n if (ajvFormatOptions) {\n addFormats(ajv, ajvFormatOptions);\n } else if (ajvFormatOptions !== false) {\n addFormats(ajv);\n }\n\n // add custom formats\n ajv.addFormat('data-url', DATA_URL_FORMAT_REGEX);\n ajv.addFormat('color', COLOR_FORMAT_REGEX);\n\n // Add RJSF-specific additional properties keywords so Ajv doesn't report errors if strict is enabled.\n ajv.addKeyword(ADDITIONAL_PROPERTY_FLAG);\n ajv.addKeyword(RJSF_ADDITONAL_PROPERTIES_FLAG);\n\n // add more schemas to validate against\n if (Array.isArray(additionalMetaSchemas)) {\n ajv.addMetaSchema(additionalMetaSchemas);\n }\n\n // add more custom formats to validate against\n if (isObject(customFormats)) {\n Object.keys(customFormats).forEach((formatName) => {\n ajv.addFormat(formatName, customFormats[formatName]);\n });\n }\n\n return ajv;\n}\n", "import { ErrorObject } from 'ajv';\nimport get from 'lodash/get';\nimport {\n createErrorHandler,\n CustomValidator,\n ErrorTransformer,\n FormContextType,\n getDefaultFormState,\n getUiOptions,\n PROPERTIES_KEY,\n RJSFSchema,\n RJSFValidationError,\n StrictRJSFSchema,\n toErrorSchema,\n UiSchema,\n unwrapErrorHandler,\n validationDataMerge,\n ValidatorType,\n} from '@rjsf/utils';\n\nexport type RawValidationErrorsType<Result = any> = { errors?: Result[]; validationError?: Error };\n\n/** Transforming the error output from ajv to format used by @rjsf/utils.\n * At some point, components should be updated to support ajv.\n *\n * @param errors - The list of AJV errors to convert to `RJSFValidationErrors`\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\nexport function transformRJSFValidationErrors<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(errors: ErrorObject[] = [], uiSchema?: UiSchema<T, S, F>): RJSFValidationError[] {\n return errors.map((e: ErrorObject) => {\n const { instancePath, keyword, params, schemaPath, parentSchema, ...rest } = e;\n let { message = '' } = rest;\n let property = instancePath.replace(/\\//g, '.');\n let stack = `${property} ${message}`.trim();\n\n if ('missingProperty' in params) {\n property = property ? `${property}.${params.missingProperty}` : params.missingProperty;\n const currentProperty: string = params.missingProperty;\n const uiSchemaTitle = getUiOptions(get(uiSchema, `${property.replace(/^\\./, '')}`)).title;\n\n if (uiSchemaTitle) {\n message = message.replace(currentProperty, uiSchemaTitle);\n } else {\n const parentSchemaTitle = get(parentSchema, [PROPERTIES_KEY, currentProperty, 'title']);\n\n if (parentSchemaTitle) {\n message = message.replace(currentProperty, parentSchemaTitle);\n }\n }\n\n stack = message;\n } else {\n const uiSchemaTitle = getUiOptions<T, S, F>(get(uiSchema, `${property.replace(/^\\./, '')}`)).title;\n\n if (uiSchemaTitle) {\n stack = `'${uiSchemaTitle}' ${message}`.trim();\n } else {\n const parentSchemaTitle = parentSchema?.title;\n\n if (parentSchemaTitle) {\n stack = `'${parentSchemaTitle}' ${message}`.trim();\n }\n }\n }\n\n // put data in expected format\n return {\n name: keyword,\n property,\n message,\n params, // specific to ajv\n stack,\n schemaPath,\n };\n });\n}\n\n/** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param validator - The `ValidatorType` implementation used for the `getDefaultFormState()` call\n * @param rawErrors - The list of raw `ErrorObject`s to process\n * @param formData - The form data to validate\n * @param schema - The schema against which to validate the form data\n * @param [customValidate] - An optional function that is used to perform custom validation\n * @param [transformErrors] - An optional function that is used to transform errors after AJV validation\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\nexport default function processRawValidationErrors<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(\n validator: ValidatorType<T, S, F>,\n rawErrors: RawValidationErrorsType<ErrorObject>,\n formData: T | undefined,\n schema: S,\n customValidate?: CustomValidator<T, S, F>,\n transformErrors?: ErrorTransformer<T, S, F>,\n uiSchema?: UiSchema<T, S, F>\n) {\n const { validationError: invalidSchemaError } = rawErrors;\n let errors = transformRJSFValidationErrors<T, S, F>(rawErrors.errors, uiSchema);\n\n if (invalidSchemaError) {\n errors = [...errors, { stack: invalidSchemaError!.message }];\n }\n if (typeof transformErrors === 'function') {\n errors = transformErrors(errors, uiSchema);\n }\n\n let errorSchema = toErrorSchema<T>(errors);\n\n if (invalidSchemaError) {\n errorSchema = {\n ...errorSchema,\n $schema: {\n __errors: [invalidSchemaError!.message],\n },\n };\n }\n\n if (typeof customValidate !== 'function') {\n return { errors, errorSchema };\n }\n\n // Include form data with undefined values, which is required for custom validation.\n const newFormData = getDefaultFormState<T, S, F>(validator, schema, formData, schema, true) as T;\n\n const errorHandler = customValidate(newFormData, createErrorHandler<T>(newFormData), uiSchema);\n const userErrorSchema = unwrapErrorHandler<T>(errorHandler);\n return validationDataMerge<T>({ errors, errorSchema }, userErrorSchema);\n}\n", "import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '@rjsf/utils';\n\nimport { CustomValidatorOptionsType, Localizer } from './types';\nimport AJV8Validator from './validator';\n\n/** Creates and returns a customized implementation of the `ValidatorType` with the given customization `options` if\n * provided. If a `localizer` is provided, it is used to translate the messages generated by the underlying AJV\n * validation.\n *\n * @param [options={}] - The `CustomValidatorOptionsType` options that are used to create the `ValidatorType` instance\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n * @returns - The custom validator implementation resulting from the set of parameters provided\n */\nexport default function customizeValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(options: CustomValidatorOptionsType = {}, localizer?: Localizer): ValidatorType<T, S, F> {\n return new AJV8Validator<T, S, F>(options, localizer);\n}\n", "import { ErrorObject } from 'ajv';\nimport get from 'lodash/get';\nimport isEqual from 'lodash/isEqual';\nimport {\n CustomValidator,\n ErrorSchema,\n ErrorTransformer,\n FormContextType,\n hashForSchema,\n ID_KEY,\n JUNK_OPTION_ID,\n RJSFSchema,\n StrictRJSFSchema,\n toErrorList,\n UiSchema,\n ValidationData,\n ValidatorType,\n retrieveSchema,\n} from '@rjsf/utils';\n\nimport { CompiledValidateFunction, Localizer, ValidatorFunctions } from './types';\nimport processRawValidationErrors, { RawValidationErrorsType } from './processRawValidationErrors';\n\n/** `ValidatorType` implementation that uses an AJV 8 precompiled validator as created by the\n * `compileSchemaValidators()` function provided by the `@rjsf/validator-ajv8` library.\n */\nexport default class AJV8PrecompiledValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n> implements ValidatorType<T, S, F>\n{\n /** The root schema object used to construct this validator\n *\n * @private\n */\n readonly rootSchema: S;\n\n /** The `ValidatorFunctions` map used to construct this validator\n *\n * @private\n */\n readonly validateFns: ValidatorFunctions;\n\n /** The main validator function associated with the base schema in the `precompiledValidator`\n *\n * @private\n */\n readonly mainValidator: CompiledValidateFunction;\n\n /** The Localizer function to use for localizing Ajv errors\n *\n * @private\n */\n readonly localizer?: Localizer;\n\n /** Constructs an `AJV8PrecompiledValidator` instance using the `validateFns` and `rootSchema`\n *\n * @param validateFns - The map of the validation functions that are generated by the `schemaCompile()` function\n * @param rootSchema - The root schema that was used with the `compileSchema()` function\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n * @throws - Error when the base schema of the precompiled validator does not have a matching validator function\n */\n constructor(validateFns: ValidatorFunctions, rootSchema: S, localizer?: Localizer) {\n this.rootSchema = rootSchema;\n this.validateFns = validateFns;\n this.localizer = localizer;\n this.mainValidator = this.getValidator(rootSchema);\n }\n\n /** Returns the precompiled validator associated with the given `schema` from the map of precompiled validator\n * functions.\n *\n * @param schema - The schema for which a precompiled validator function is desired\n * @returns - The precompiled validator function associated with this schema\n */\n getValidator(schema: S) {\n const key = get(schema, ID_KEY) || hashForSchema(schema);\n const validator = this.validateFns[key];\n if (!validator) {\n throw new Error(`No precompiled validator function was found for the given schema for \"${key}\"`);\n }\n return validator;\n }\n\n /** Converts an `errorSchema` into a list of `RJSFValidationErrors`\n *\n * @param errorSchema - The `ErrorSchema` instance to convert\n * @param [fieldPath=[]] - The current field path, defaults to [] if not specified\n * @deprecated - Use the `toErrorList()` function provided by `@rjsf/utils` instead. This function will be removed in\n * the next major release.\n */\n toErrorList(errorSchema?: ErrorSchema<T>, fieldPath: string[] = []) {\n return toErrorList(errorSchema, fieldPath);\n }\n\n /** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use\n * by the playground. Returns the `errors` from the validation\n *\n * @param schema - The schema against which to validate the form data * @param schema\n * @param formData - The form data to validate\n * @throws - Error when the schema provided does not match the base schema of the precompiled validator\n */\n rawValidation<Result = any>(schema: S, formData?: T): RawValidationErrorsType<Result> {\n const resolvedRootSchema = retrieveSchema(this, this.rootSchema, this.rootSchema, formData);\n if (!isEqual(schema, resolvedRootSchema)) {\n throw new Error(\n 'The schema associated with the precompiled schema differs from the schema provided for validation'\n );\n }\n this.mainValidator(formData);\n\n if (typeof this.localizer === 'function') {\n this.localizer(this.mainValidator.errors);\n }\n const errors = this.mainValidator.errors || undefined;\n\n // Clear errors to prevent persistent errors, see #1104\n this.mainValidator.errors = null;\n\n return { errors: errors as unknown as Result[] };\n }\n\n /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param formData - The form data to validate\n * @param schema - The schema against which to validate the form data\n * @param [customValidate] - An optional function that is used to perform custom validation\n * @param [transformErrors] - An optional function that is used to transform errors after AJV validation\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\n validateFormData(\n formData: T | undefined,\n schema: S,\n customValidate?: CustomValidator<T, S, F>,\n transformErrors?: ErrorTransformer<T, S, F>,\n uiSchema?: UiSchema<T, S, F>\n ): ValidationData<T> {\n const rawErrors = this.rawValidation<ErrorObject>(schema, formData);\n return processRawValidationErrors(this, rawErrors, formData, schema, customValidate, transformErrors, uiSchema);\n }\n\n /** Validates data against a schema, returning true if the data is valid, or false otherwise. If the schema is\n * invalid, then this function will return false.\n *\n * @param schema - The schema against which to validate the form data\n * @param formData - The form data to validate\n * @param rootSchema - The root schema used to provide $ref resolutions\n * @returns - true if the formData validates against the schema, false otherwise\n * @throws - Error when the schema provided does not match the base schema of the precompiled validator OR if there\n * isn't a precompiled validator function associated with the schema\n */\n isValid(schema: S, formData: T | undefined, rootSchema: S) {\n if (!isEqual(rootSchema, this.rootSchema)) {\n throw new Error(\n 'The schema associated with the precompiled validator differs from the rootSchema provided for validation'\n );\n }\n if (get(schema, ID_KEY) === JUNK_OPTION_ID) {\n return false;\n }\n const validator = this.getValidator(schema);\n return validator(formData);\n }\n}\n", "import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '@rjsf/utils';\n\nimport { Localizer, ValidatorFunctions } from './types';\nimport AJV8PrecompiledValidator from './precompiledValidator';\n\n/** Creates and returns a `ValidatorType` interface that is implemented with a precompiled validator. If a `localizer`\n * is provided, it is used to translate the messages generated by the underlying AJV validation.\n *\n * NOTE: The `validateFns` parameter is an object obtained by importing from a precompiled validation file created via\n * the `compileSchemaValidators()` function.\n *\n * @param validateFns - The map of the validation functions that are created by the `compileSchemaValidators()` function\n * @param rootSchema - The root schema that was used with the `compileSchemaValidators()` function\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n * @returns - The precompiled validator implementation resulting from the set of parameters provided\n */\nexport default function createPrecompiledValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(validateFns: ValidatorFunctions, rootSchema: S, localizer?: Localizer): ValidatorType<T, S, F> {\n return new AJV8PrecompiledValidator<T, S, F>(validateFns, rootSchema, localizer);\n}\n", "import customizeValidator from './customizeValidator';\nimport createPrecompiledValidator from './createPrecompiledValidator';\n\nexport { customizeValidator, createPrecompiledValidator };\nexport * from './types';\n\nexport default customizeValidator();\n"],
|
|
5
|
-
"mappings": ";AACA;AAAA,EAKE;AAAA,EAEA;AAAA,EAEA;AAAA,EAIA;AAAA,EACA;AAAA,OACK;;;AChBP,OAAO,SAAsB;AAC7B,OAAO,gBAA0C;AACjD,OAAO,cAAc;AAGrB,SAAS,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AAkB,MAAM;AAAA,MACzC;AACA,eAAS,kBAAkB,UAAU;AAGrC,wBAAkB,SAAS;AAAA,IAC7B;AAEA,WAAO;AAAA,MACL;AAAA,MACA,iBAAiB;AAAA,IACnB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,iBACE,UACA,QACA,gBACA,iBACA,UACmB;AACnB,UAAM,YAAY,KAAK,cAA2B,QAAQ,QAAQ;AAClE,WAAO,2BAA2B,MAAM,WAAW,UAAU,QAAQ,gBAAgB,iBAAiB,QAAQ;AAAA,EAChH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,QAAQ,QAAW,UAAyB,YAAe;AACzD,UAAM,eAAe,WAAW,MAAM,KAAK;AAC3C,QAAI;
|
|
4
|
+
"sourcesContent": ["import Ajv, { ErrorObject, ValidateFunction } from 'ajv';\nimport {\n CustomValidator,\n ErrorSchema,\n ErrorTransformer,\n FormContextType,\n ID_KEY,\n RJSFSchema,\n ROOT_SCHEMA_PREFIX,\n StrictRJSFSchema,\n toErrorList,\n UiSchema,\n ValidationData,\n ValidatorType,\n withIdRefPrefix,\n hashForSchema,\n} from '@rjsf/utils';\n\nimport { CustomValidatorOptionsType, Localizer } from './types';\nimport createAjvInstance from './createAjvInstance';\nimport processRawValidationErrors, { RawValidationErrorsType } from './processRawValidationErrors';\n\n/** `ValidatorType` implementation that uses the AJV 8 validation mechanism.\n */\nexport default class AJV8Validator<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>\n implements ValidatorType<T, S, F>\n{\n /** The AJV instance to use for all validations\n *\n * @private\n */\n private ajv: Ajv;\n\n /** The Localizer function to use for localizing Ajv errors\n *\n * @private\n */\n readonly localizer?: Localizer;\n\n /** Constructs an `AJV8Validator` instance using the `options`\n *\n * @param options - The `CustomValidatorOptionsType` options that are used to create the AJV instance\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n */\n constructor(options: CustomValidatorOptionsType, localizer?: Localizer) {\n const { additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass } = options;\n this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass);\n this.localizer = localizer;\n }\n\n /** Converts an `errorSchema` into a list of `RJSFValidationErrors`\n *\n * @param errorSchema - The `ErrorSchema` instance to convert\n * @param [fieldPath=[]] - The current field path, defaults to [] if not specified\n * @deprecated - Use the `toErrorList()` function provided by `@rjsf/utils` instead. This function will be removed in\n * the next major release.\n */\n toErrorList(errorSchema?: ErrorSchema<T>, fieldPath: string[] = []) {\n return toErrorList(errorSchema, fieldPath);\n }\n\n /** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use\n * by the playground. Returns the `errors` from the validation\n *\n * @param schema - The schema against which to validate the form data * @param schema\n * @param formData - The form data to validate\n */\n rawValidation<Result = any>(schema: S, formData?: T): RawValidationErrorsType<Result> {\n let compilationError: Error | undefined = undefined;\n let compiledValidator: ValidateFunction | undefined;\n if (schema[ID_KEY]) {\n compiledValidator = this.ajv.getSchema(schema[ID_KEY]);\n }\n try {\n if (compiledValidator === undefined) {\n compiledValidator = this.ajv.compile(schema);\n }\n compiledValidator(formData);\n } catch (err) {\n compilationError = err as Error;\n }\n\n let errors;\n if (compiledValidator) {\n if (typeof this.localizer === 'function') {\n this.localizer(compiledValidator.errors);\n }\n errors = compiledValidator.errors || undefined;\n\n // Clear errors to prevent persistent errors, see #1104\n compiledValidator.errors = null;\n }\n\n return {\n errors: errors as unknown as Result[],\n validationError: compilationError,\n };\n }\n\n /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param formData - The form data to validate\n * @param schema - The schema against which to validate the form data\n * @param [customValidate] - An optional function that is used to perform custom validation\n * @param [transformErrors] - An optional function that is used to transform errors after AJV validation\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\n validateFormData(\n formData: T | undefined,\n schema: S,\n customValidate?: CustomValidator<T, S, F>,\n transformErrors?: ErrorTransformer<T, S, F>,\n uiSchema?: UiSchema<T, S, F>\n ): ValidationData<T> {\n const rawErrors = this.rawValidation<ErrorObject>(schema, formData);\n return processRawValidationErrors(this, rawErrors, formData, schema, customValidate, transformErrors, uiSchema);\n }\n\n /** Validates data against a schema, returning true if the data is valid, or\n * false otherwise. If the schema is invalid, then this function will return\n * false.\n *\n * @param schema - The schema against which to validate the form data\n * @param formData - The form data to validate\n * @param rootSchema - The root schema used to provide $ref resolutions\n */\n isValid(schema: S, formData: T | undefined, rootSchema: S) {\n const rootSchemaId = rootSchema[ID_KEY] ?? ROOT_SCHEMA_PREFIX;\n try {\n // add the rootSchema ROOT_SCHEMA_PREFIX as id.\n // then rewrite the schema ref's to point to the rootSchema\n // this accounts for the case where schema have references to models\n // that lives in the rootSchema but not in the schema in question.\n // if (this.ajv.getSchema(rootSchemaId) === undefined) {\n // TODO restore the commented out `if` above when the TODO in the `finally` is completed\n this.ajv.addSchema(rootSchema, rootSchemaId);\n // }\n const schemaWithIdRefPrefix = withIdRefPrefix<S>(schema) as S;\n const schemaId = schemaWithIdRefPrefix[ID_KEY] ?? hashForSchema(schemaWithIdRefPrefix);\n let compiledValidator: ValidateFunction | undefined;\n compiledValidator = this.ajv.getSchema(schemaId);\n if (compiledValidator === undefined) {\n // Add schema by an explicit ID so it can be fetched later\n // Fall back to using compile if necessary\n // https://ajv.js.org/guide/managing-schemas.html#pre-adding-all-schemas-vs-adding-on-demand\n compiledValidator =\n this.ajv.addSchema(schemaWithIdRefPrefix, schemaId).getSchema(schemaId) ||\n this.ajv.compile(schemaWithIdRefPrefix);\n }\n const result = compiledValidator(formData);\n return result as boolean;\n } catch (e) {\n console.warn('Error encountered compiling schema:', e);\n return false;\n } finally {\n // TODO: A function should be called if the root schema changes so we don't have to remove and recompile the schema every run.\n // make sure we remove the rootSchema from the global ajv instance\n this.ajv.removeSchema(rootSchemaId);\n }\n }\n}\n", "import Ajv, { Options } from 'ajv';\nimport addFormats, { FormatsPluginOptions } from 'ajv-formats';\nimport isObject from 'lodash/isObject';\n\nimport { CustomValidatorOptionsType } from './types';\nimport { ADDITIONAL_PROPERTY_FLAG, RJSF_ADDITONAL_PROPERTIES_FLAG } from '@rjsf/utils';\n\nexport const AJV_CONFIG: Options = {\n allErrors: true,\n multipleOfPrecision: 8,\n strict: false,\n verbose: true,\n} as const;\nexport const COLOR_FORMAT_REGEX =\n /^(#?([0-9A-Fa-f]{3}){1,2}\\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\\(\\s*\\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\b\\s*,\\s*\\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\b\\s*,\\s*\\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\b\\s*\\))|(rgb\\(\\s*(\\d?\\d%|100%)+\\s*,\\s*(\\d?\\d%|100%)+\\s*,\\s*(\\d?\\d%|100%)+\\s*\\)))$/;\nexport const DATA_URL_FORMAT_REGEX = /^data:([a-z]+\\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;\n\n/** Creates an Ajv version 8 implementation object with standard support for the 'color` and `data-url` custom formats.\n * If `additionalMetaSchemas` are provided then the Ajv instance is modified to add each of the meta schemas in the\n * list. If `customFormats` are provided then those additional formats are added to the list of supported formats. If\n * `ajvOptionsOverrides` are provided then they are spread on top of the default `AJV_CONFIG` options when constructing\n * the `Ajv` instance. With Ajv v8, the JSON Schema formats are not provided by default, but can be plugged in. By\n * default, all formats from the `ajv-formats` library are added. To disable this capability, set the `ajvFormatOptions`\n * parameter to `false`. Additionally, you can configure the `ajv-formats` by providing a custom set of\n * [format options](https://github.com/ajv-validator/ajv-formats) to the `ajvFormatOptions` parameter.\n *\n * @param [additionalMetaSchemas] - The list of additional meta schemas that the validator can access\n * @param [customFormats] - The set of additional custom formats that the validator will support\n * @param [ajvOptionsOverrides={}] - The set of validator config override options\n * @param [ajvFormatOptions] - The `ajv-format` options to use when adding formats to `ajv`; pass `false` to disable it\n * @param [AjvClass] - The `Ajv` class to use when creating the validator instance\n */\nexport default function createAjvInstance(\n additionalMetaSchemas?: CustomValidatorOptionsType['additionalMetaSchemas'],\n customFormats?: CustomValidatorOptionsType['customFormats'],\n ajvOptionsOverrides: CustomValidatorOptionsType['ajvOptionsOverrides'] = {},\n ajvFormatOptions?: FormatsPluginOptions | false,\n AjvClass: typeof Ajv = Ajv\n) {\n const ajv = new AjvClass({ ...AJV_CONFIG, ...ajvOptionsOverrides });\n if (ajvFormatOptions) {\n addFormats(ajv, ajvFormatOptions);\n } else if (ajvFormatOptions !== false) {\n addFormats(ajv);\n }\n\n // add custom formats\n ajv.addFormat('data-url', DATA_URL_FORMAT_REGEX);\n ajv.addFormat('color', COLOR_FORMAT_REGEX);\n\n // Add RJSF-specific additional properties keywords so Ajv doesn't report errors if strict is enabled.\n ajv.addKeyword(ADDITIONAL_PROPERTY_FLAG);\n ajv.addKeyword(RJSF_ADDITONAL_PROPERTIES_FLAG);\n\n // add more schemas to validate against\n if (Array.isArray(additionalMetaSchemas)) {\n ajv.addMetaSchema(additionalMetaSchemas);\n }\n\n // add more custom formats to validate against\n if (isObject(customFormats)) {\n Object.keys(customFormats).forEach((formatName) => {\n ajv.addFormat(formatName, customFormats[formatName]);\n });\n }\n\n return ajv;\n}\n", "import { ErrorObject } from 'ajv';\nimport get from 'lodash/get';\nimport {\n createErrorHandler,\n CustomValidator,\n ErrorTransformer,\n FormContextType,\n getDefaultFormState,\n getUiOptions,\n PROPERTIES_KEY,\n RJSFSchema,\n RJSFValidationError,\n StrictRJSFSchema,\n toErrorSchema,\n UiSchema,\n unwrapErrorHandler,\n validationDataMerge,\n ValidatorType,\n} from '@rjsf/utils';\n\nexport type RawValidationErrorsType<Result = any> = { errors?: Result[]; validationError?: Error };\n\n/** Transforming the error output from ajv to format used by @rjsf/utils.\n * At some point, components should be updated to support ajv.\n *\n * @param errors - The list of AJV errors to convert to `RJSFValidationErrors`\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\nexport function transformRJSFValidationErrors<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(errors: ErrorObject[] = [], uiSchema?: UiSchema<T, S, F>): RJSFValidationError[] {\n return errors.map((e: ErrorObject) => {\n const { instancePath, keyword, params, schemaPath, parentSchema, ...rest } = e;\n let { message = '' } = rest;\n let property = instancePath.replace(/\\//g, '.');\n let stack = `${property} ${message}`.trim();\n\n if ('missingProperty' in params) {\n property = property ? `${property}.${params.missingProperty}` : params.missingProperty;\n const currentProperty: string = params.missingProperty;\n const uiSchemaTitle = getUiOptions(get(uiSchema, `${property.replace(/^\\./, '')}`)).title;\n\n if (uiSchemaTitle) {\n message = message.replace(currentProperty, uiSchemaTitle);\n } else {\n const parentSchemaTitle = get(parentSchema, [PROPERTIES_KEY, currentProperty, 'title']);\n\n if (parentSchemaTitle) {\n message = message.replace(currentProperty, parentSchemaTitle);\n }\n }\n\n stack = message;\n } else {\n const uiSchemaTitle = getUiOptions<T, S, F>(get(uiSchema, `${property.replace(/^\\./, '')}`)).title;\n\n if (uiSchemaTitle) {\n stack = `'${uiSchemaTitle}' ${message}`.trim();\n } else {\n const parentSchemaTitle = parentSchema?.title;\n\n if (parentSchemaTitle) {\n stack = `'${parentSchemaTitle}' ${message}`.trim();\n }\n }\n }\n\n // put data in expected format\n return {\n name: keyword,\n property,\n message,\n params, // specific to ajv\n stack,\n schemaPath,\n };\n });\n}\n\n/** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param validator - The `ValidatorType` implementation used for the `getDefaultFormState()` call\n * @param rawErrors - The list of raw `ErrorObject`s to process\n * @param formData - The form data to validate\n * @param schema - The schema against which to validate the form data\n * @param [customValidate] - An optional function that is used to perform custom validation\n * @param [transformErrors] - An optional function that is used to transform errors after AJV validation\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\nexport default function processRawValidationErrors<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(\n validator: ValidatorType<T, S, F>,\n rawErrors: RawValidationErrorsType<ErrorObject>,\n formData: T | undefined,\n schema: S,\n customValidate?: CustomValidator<T, S, F>,\n transformErrors?: ErrorTransformer<T, S, F>,\n uiSchema?: UiSchema<T, S, F>\n) {\n const { validationError: invalidSchemaError } = rawErrors;\n let errors = transformRJSFValidationErrors<T, S, F>(rawErrors.errors, uiSchema);\n\n if (invalidSchemaError) {\n errors = [...errors, { stack: invalidSchemaError!.message }];\n }\n if (typeof transformErrors === 'function') {\n errors = transformErrors(errors, uiSchema);\n }\n\n let errorSchema = toErrorSchema<T>(errors);\n\n if (invalidSchemaError) {\n errorSchema = {\n ...errorSchema,\n $schema: {\n __errors: [invalidSchemaError!.message],\n },\n };\n }\n\n if (typeof customValidate !== 'function') {\n return { errors, errorSchema };\n }\n\n // Include form data with undefined values, which is required for custom validation.\n const newFormData = getDefaultFormState<T, S, F>(validator, schema, formData, schema, true) as T;\n\n const errorHandler = customValidate(newFormData, createErrorHandler<T>(newFormData), uiSchema);\n const userErrorSchema = unwrapErrorHandler<T>(errorHandler);\n return validationDataMerge<T>({ errors, errorSchema }, userErrorSchema);\n}\n", "import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '@rjsf/utils';\n\nimport { CustomValidatorOptionsType, Localizer } from './types';\nimport AJV8Validator from './validator';\n\n/** Creates and returns a customized implementation of the `ValidatorType` with the given customization `options` if\n * provided. If a `localizer` is provided, it is used to translate the messages generated by the underlying AJV\n * validation.\n *\n * @param [options={}] - The `CustomValidatorOptionsType` options that are used to create the `ValidatorType` instance\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n * @returns - The custom validator implementation resulting from the set of parameters provided\n */\nexport default function customizeValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(options: CustomValidatorOptionsType = {}, localizer?: Localizer): ValidatorType<T, S, F> {\n return new AJV8Validator<T, S, F>(options, localizer);\n}\n", "import { ErrorObject } from 'ajv';\nimport get from 'lodash/get';\nimport isEqual from 'lodash/isEqual';\nimport {\n CustomValidator,\n ErrorSchema,\n ErrorTransformer,\n FormContextType,\n hashForSchema,\n ID_KEY,\n JUNK_OPTION_ID,\n RJSFSchema,\n StrictRJSFSchema,\n toErrorList,\n UiSchema,\n ValidationData,\n ValidatorType,\n retrieveSchema,\n} from '@rjsf/utils';\n\nimport { CompiledValidateFunction, Localizer, ValidatorFunctions } from './types';\nimport processRawValidationErrors, { RawValidationErrorsType } from './processRawValidationErrors';\n\n/** `ValidatorType` implementation that uses an AJV 8 precompiled validator as created by the\n * `compileSchemaValidators()` function provided by the `@rjsf/validator-ajv8` library.\n */\nexport default class AJV8PrecompiledValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n> implements ValidatorType<T, S, F>\n{\n /** The root schema object used to construct this validator\n *\n * @private\n */\n readonly rootSchema: S;\n\n /** The `ValidatorFunctions` map used to construct this validator\n *\n * @private\n */\n readonly validateFns: ValidatorFunctions;\n\n /** The main validator function associated with the base schema in the `precompiledValidator`\n *\n * @private\n */\n readonly mainValidator: CompiledValidateFunction;\n\n /** The Localizer function to use for localizing Ajv errors\n *\n * @private\n */\n readonly localizer?: Localizer;\n\n /** Constructs an `AJV8PrecompiledValidator` instance using the `validateFns` and `rootSchema`\n *\n * @param validateFns - The map of the validation functions that are generated by the `schemaCompile()` function\n * @param rootSchema - The root schema that was used with the `compileSchema()` function\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n * @throws - Error when the base schema of the precompiled validator does not have a matching validator function\n */\n constructor(validateFns: ValidatorFunctions, rootSchema: S, localizer?: Localizer) {\n this.rootSchema = rootSchema;\n this.validateFns = validateFns;\n this.localizer = localizer;\n this.mainValidator = this.getValidator(rootSchema);\n }\n\n /** Returns the precompiled validator associated with the given `schema` from the map of precompiled validator\n * functions.\n *\n * @param schema - The schema for which a precompiled validator function is desired\n * @returns - The precompiled validator function associated with this schema\n */\n getValidator(schema: S) {\n const key = get(schema, ID_KEY) || hashForSchema(schema);\n const validator = this.validateFns[key];\n if (!validator) {\n throw new Error(`No precompiled validator function was found for the given schema for \"${key}\"`);\n }\n return validator;\n }\n\n /** Ensures that the validator is using the same schema as the root schema used to construct the precompiled\n * validator. It first compares the given `schema` against the root schema and if they aren't the same, then it\n * checks against the resolved root schema, on the chance that a resolved version of the root schema was passed in\n * instead of the raw root schema.\n *\n * @param schema - The schema against which to validate the form data\n * @param [formData] - The form data to validate if any\n */\n ensureSameRootSchema(schema: S, formData?: T) {\n if (!isEqual(schema, this.rootSchema)) {\n // Resolve the root schema with the passed in form data since that may affect the resolution\n const resolvedRootSchema = retrieveSchema(this, this.rootSchema, this.rootSchema, formData);\n if (!isEqual(schema, resolvedRootSchema)) {\n throw new Error(\n 'The schema associated with the precompiled validator differs from the rootSchema provided for validation'\n );\n }\n }\n return true;\n }\n\n /** Converts an `errorSchema` into a list of `RJSFValidationErrors`\n *\n * @param errorSchema - The `ErrorSchema` instance to convert\n * @param [fieldPath=[]] - The current field path, defaults to [] if not specified\n * @deprecated - Use the `toErrorList()` function provided by `@rjsf/utils` instead. This function will be removed in\n * the next major release.\n */\n toErrorList(errorSchema?: ErrorSchema<T>, fieldPath: string[] = []) {\n return toErrorList(errorSchema, fieldPath);\n }\n\n /** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use\n * by the playground. Returns the `errors` from the validation\n *\n * @param schema - The schema against which to validate the form data\n * @param [formData] - The form data to validate, if any\n * @throws - Error when the schema provided does not match the base schema of the precompiled validator\n */\n rawValidation<Result = any>(schema: S, formData?: T): RawValidationErrorsType<Result> {\n this.ensureSameRootSchema(schema, formData);\n this.mainValidator(formData);\n\n if (typeof this.localizer === 'function') {\n this.localizer(this.mainValidator.errors);\n }\n const errors = this.mainValidator.errors || undefined;\n\n // Clear errors to prevent persistent errors, see #1104\n this.mainValidator.errors = null;\n\n return { errors: errors as unknown as Result[] };\n }\n\n /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param formData - The form data to validate\n * @param schema - The schema against which to validate the form data\n * @param [customValidate] - An optional function that is used to perform custom validation\n * @param [transformErrors] - An optional function that is used to transform errors after AJV validation\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\n validateFormData(\n formData: T | undefined,\n schema: S,\n customValidate?: CustomValidator<T, S, F>,\n transformErrors?: ErrorTransformer<T, S, F>,\n uiSchema?: UiSchema<T, S, F>\n ): ValidationData<T> {\n const rawErrors = this.rawValidation<ErrorObject>(schema, formData);\n return processRawValidationErrors(this, rawErrors, formData, schema, customValidate, transformErrors, uiSchema);\n }\n\n /** Validates data against a schema, returning true if the data is valid, or false otherwise. If the schema is\n * invalid, then this function will return false.\n *\n * @param schema - The schema against which to validate the form data\n * @param formData - The form data to validate\n * @param rootSchema - The root schema used to provide $ref resolutions\n * @returns - true if the formData validates against the schema, false otherwise\n * @throws - Error when the schema provided does not match the base schema of the precompiled validator OR if there\n * isn't a precompiled validator function associated with the schema\n */\n isValid(schema: S, formData: T | undefined, rootSchema: S) {\n this.ensureSameRootSchema(rootSchema, formData);\n if (get(schema, ID_KEY) === JUNK_OPTION_ID) {\n return false;\n }\n const validator = this.getValidator(schema);\n return validator(formData);\n }\n}\n", "import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '@rjsf/utils';\n\nimport { Localizer, ValidatorFunctions } from './types';\nimport AJV8PrecompiledValidator from './precompiledValidator';\n\n/** Creates and returns a `ValidatorType` interface that is implemented with a precompiled validator. If a `localizer`\n * is provided, it is used to translate the messages generated by the underlying AJV validation.\n *\n * NOTE: The `validateFns` parameter is an object obtained by importing from a precompiled validation file created via\n * the `compileSchemaValidators()` function.\n *\n * @param validateFns - The map of the validation functions that are created by the `compileSchemaValidators()` function\n * @param rootSchema - The root schema that was used with the `compileSchemaValidators()` function\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n * @returns - The precompiled validator implementation resulting from the set of parameters provided\n */\nexport default function createPrecompiledValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(validateFns: ValidatorFunctions, rootSchema: S, localizer?: Localizer): ValidatorType<T, S, F> {\n return new AJV8PrecompiledValidator<T, S, F>(validateFns, rootSchema, localizer);\n}\n", "import customizeValidator from './customizeValidator';\nimport createPrecompiledValidator from './createPrecompiledValidator';\n\nexport { customizeValidator, createPrecompiledValidator };\nexport * from './types';\n\nexport default customizeValidator();\n"],
|
|
5
|
+
"mappings": ";AACA;AAAA,EAKE;AAAA,EAEA;AAAA,EAEA;AAAA,EAIA;AAAA,EACA;AAAA,OACK;;;AChBP,OAAO,SAAsB;AAC7B,OAAO,gBAA0C;AACjD,OAAO,cAAc;AAGrB,SAAS,0BAA0B,sCAAsC;AAElE,IAAM,aAAsB;AAAA,EACjC,WAAW;AAAA,EACX,qBAAqB;AAAA,EACrB,QAAQ;AAAA,EACR,SAAS;AACX;AACO,IAAM,qBACX;AACK,IAAM,wBAAwB;AAiBtB,SAAR,kBACL,uBACA,eACA,sBAAyE,CAAC,GAC1E,kBACA,WAAuB,KACvB;AACA,QAAM,MAAM,IAAI,SAAS,EAA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iB,QAAQ;AAAA,EAChH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,QAAQ,QAAW,UAAyB,YAAe;AACzD,SAAK,qBAAqB,YAAY,QAAQ;AAC9C,QAAIH,KAAI,QAAQC,OAAM,MAAM,gBAAgB;AAC1C,aAAO;AAAA,IACT;AACA,UAAM,YAAY,KAAK,aAAa,MAAM;AAC1C,WAAO,UAAU,QAAQ;AAAA,EAC3B;AACF;;;ACnKe,SAAR,2BAIL,aAAiC,YAAe,WAA+C;AAC/F,SAAO,IAAI,yBAAkC,aAAa,YAAY,SAAS;AACjF;;;AChBA,IAAO,cAAQ,mBAAmB;",
|
|
6
6
|
"names": ["get", "hashForSchema", "ID_KEY", "toErrorList", "get", "ID_KEY", "hashForSchema", "toErrorList"]
|
|
7
7
|
}
|
|
@@ -183,9 +183,7 @@
|
|
|
183
183
|
isValid(schema, formData, rootSchema) {
|
|
184
184
|
const rootSchemaId = rootSchema[utils.ID_KEY] ?? utils.ROOT_SCHEMA_PREFIX;
|
|
185
185
|
try {
|
|
186
|
-
|
|
187
|
-
this.ajv.addSchema(rootSchema, rootSchemaId);
|
|
188
|
-
}
|
|
186
|
+
this.ajv.addSchema(rootSchema, rootSchemaId);
|
|
189
187
|
const schemaWithIdRefPrefix = utils.withIdRefPrefix(schema);
|
|
190
188
|
const schemaId = schemaWithIdRefPrefix[utils.ID_KEY] ?? utils.hashForSchema(schemaWithIdRefPrefix);
|
|
191
189
|
let compiledValidator;
|
|
@@ -236,6 +234,25 @@
|
|
|
236
234
|
}
|
|
237
235
|
return validator;
|
|
238
236
|
}
|
|
237
|
+
/** Ensures that the validator is using the same schema as the root schema used to construct the precompiled
|
|
238
|
+
* validator. It first compares the given `schema` against the root schema and if they aren't the same, then it
|
|
239
|
+
* checks against the resolved root schema, on the chance that a resolved version of the root schema was passed in
|
|
240
|
+
* instead of the raw root schema.
|
|
241
|
+
*
|
|
242
|
+
* @param schema - The schema against which to validate the form data
|
|
243
|
+
* @param [formData] - The form data to validate if any
|
|
244
|
+
*/
|
|
245
|
+
ensureSameRootSchema(schema, formData) {
|
|
246
|
+
if (!isEqual(schema, this.rootSchema)) {
|
|
247
|
+
const resolvedRootSchema = utils.retrieveSchema(this, this.rootSchema, this.rootSchema, formData);
|
|
248
|
+
if (!isEqual(schema, resolvedRootSchema)) {
|
|
249
|
+
throw new Error(
|
|
250
|
+
"The schema associated with the precompiled validator differs from the rootSchema provided for validation"
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
239
256
|
/** Converts an `errorSchema` into a list of `RJSFValidationErrors`
|
|
240
257
|
*
|
|
241
258
|
* @param errorSchema - The `ErrorSchema` instance to convert
|
|
@@ -249,17 +266,12 @@
|
|
|
249
266
|
/** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use
|
|
250
267
|
* by the playground. Returns the `errors` from the validation
|
|
251
268
|
*
|
|
252
|
-
* @param schema - The schema against which to validate the form data
|
|
253
|
-
* @param formData - The form data to validate
|
|
269
|
+
* @param schema - The schema against which to validate the form data
|
|
270
|
+
* @param [formData] - The form data to validate, if any
|
|
254
271
|
* @throws - Error when the schema provided does not match the base schema of the precompiled validator
|
|
255
272
|
*/
|
|
256
273
|
rawValidation(schema, formData) {
|
|
257
|
-
|
|
258
|
-
if (!isEqual(schema, resolvedRootSchema)) {
|
|
259
|
-
throw new Error(
|
|
260
|
-
"The schema associated with the precompiled schema differs from the schema provided for validation"
|
|
261
|
-
);
|
|
262
|
-
}
|
|
274
|
+
this.ensureSameRootSchema(schema, formData);
|
|
263
275
|
this.mainValidator(formData);
|
|
264
276
|
if (typeof this.localizer === "function") {
|
|
265
277
|
this.localizer(this.mainValidator.errors);
|
|
@@ -294,11 +306,7 @@
|
|
|
294
306
|
* isn't a precompiled validator function associated with the schema
|
|
295
307
|
*/
|
|
296
308
|
isValid(schema, formData, rootSchema) {
|
|
297
|
-
|
|
298
|
-
throw new Error(
|
|
299
|
-
"The schema associated with the precompiled validator differs from the rootSchema provided for validation"
|
|
300
|
-
);
|
|
301
|
-
}
|
|
309
|
+
this.ensureSameRootSchema(rootSchema, formData);
|
|
302
310
|
if (get(schema, utils.ID_KEY) === utils.JUNK_OPTION_ID) {
|
|
303
311
|
return false;
|
|
304
312
|
}
|
|
@@ -40,6 +40,15 @@ export default class AJV8PrecompiledValidator<T = any, S extends StrictRJSFSchem
|
|
|
40
40
|
* @returns - The precompiled validator function associated with this schema
|
|
41
41
|
*/
|
|
42
42
|
getValidator(schema: S): CompiledValidateFunction;
|
|
43
|
+
/** Ensures that the validator is using the same schema as the root schema used to construct the precompiled
|
|
44
|
+
* validator. It first compares the given `schema` against the root schema and if they aren't the same, then it
|
|
45
|
+
* checks against the resolved root schema, on the chance that a resolved version of the root schema was passed in
|
|
46
|
+
* instead of the raw root schema.
|
|
47
|
+
*
|
|
48
|
+
* @param schema - The schema against which to validate the form data
|
|
49
|
+
* @param [formData] - The form data to validate if any
|
|
50
|
+
*/
|
|
51
|
+
ensureSameRootSchema(schema: S, formData?: T): boolean;
|
|
43
52
|
/** Converts an `errorSchema` into a list of `RJSFValidationErrors`
|
|
44
53
|
*
|
|
45
54
|
* @param errorSchema - The `ErrorSchema` instance to convert
|
|
@@ -51,8 +60,8 @@ export default class AJV8PrecompiledValidator<T = any, S extends StrictRJSFSchem
|
|
|
51
60
|
/** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use
|
|
52
61
|
* by the playground. Returns the `errors` from the validation
|
|
53
62
|
*
|
|
54
|
-
* @param schema - The schema against which to validate the form data
|
|
55
|
-
* @param formData - The form data to validate
|
|
63
|
+
* @param schema - The schema against which to validate the form data
|
|
64
|
+
* @param [formData] - The form data to validate, if any
|
|
56
65
|
* @throws - Error when the schema provided does not match the base schema of the precompiled validator
|
|
57
66
|
*/
|
|
58
67
|
rawValidation<Result = any>(schema: S, formData?: T): RawValidationErrorsType<Result>;
|
|
@@ -33,6 +33,24 @@ export default class AJV8PrecompiledValidator {
|
|
|
33
33
|
}
|
|
34
34
|
return validator;
|
|
35
35
|
}
|
|
36
|
+
/** Ensures that the validator is using the same schema as the root schema used to construct the precompiled
|
|
37
|
+
* validator. It first compares the given `schema` against the root schema and if they aren't the same, then it
|
|
38
|
+
* checks against the resolved root schema, on the chance that a resolved version of the root schema was passed in
|
|
39
|
+
* instead of the raw root schema.
|
|
40
|
+
*
|
|
41
|
+
* @param schema - The schema against which to validate the form data
|
|
42
|
+
* @param [formData] - The form data to validate if any
|
|
43
|
+
*/
|
|
44
|
+
ensureSameRootSchema(schema, formData) {
|
|
45
|
+
if (!isEqual(schema, this.rootSchema)) {
|
|
46
|
+
// Resolve the root schema with the passed in form data since that may affect the resolution
|
|
47
|
+
const resolvedRootSchema = retrieveSchema(this, this.rootSchema, this.rootSchema, formData);
|
|
48
|
+
if (!isEqual(schema, resolvedRootSchema)) {
|
|
49
|
+
throw new Error('The schema associated with the precompiled validator differs from the rootSchema provided for validation');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
36
54
|
/** Converts an `errorSchema` into a list of `RJSFValidationErrors`
|
|
37
55
|
*
|
|
38
56
|
* @param errorSchema - The `ErrorSchema` instance to convert
|
|
@@ -46,15 +64,12 @@ export default class AJV8PrecompiledValidator {
|
|
|
46
64
|
/** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use
|
|
47
65
|
* by the playground. Returns the `errors` from the validation
|
|
48
66
|
*
|
|
49
|
-
* @param schema - The schema against which to validate the form data
|
|
50
|
-
* @param formData - The form data to validate
|
|
67
|
+
* @param schema - The schema against which to validate the form data
|
|
68
|
+
* @param [formData] - The form data to validate, if any
|
|
51
69
|
* @throws - Error when the schema provided does not match the base schema of the precompiled validator
|
|
52
70
|
*/
|
|
53
71
|
rawValidation(schema, formData) {
|
|
54
|
-
|
|
55
|
-
if (!isEqual(schema, resolvedRootSchema)) {
|
|
56
|
-
throw new Error('The schema associated with the precompiled schema differs from the schema provided for validation');
|
|
57
|
-
}
|
|
72
|
+
this.ensureSameRootSchema(schema, formData);
|
|
58
73
|
this.mainValidator(formData);
|
|
59
74
|
if (typeof this.localizer === 'function') {
|
|
60
75
|
this.localizer(this.mainValidator.errors);
|
|
@@ -90,9 +105,7 @@ export default class AJV8PrecompiledValidator {
|
|
|
90
105
|
* isn't a precompiled validator function associated with the schema
|
|
91
106
|
*/
|
|
92
107
|
isValid(schema, formData, rootSchema) {
|
|
93
|
-
|
|
94
|
-
throw new Error('The schema associated with the precompiled validator differs from the rootSchema provided for validation');
|
|
95
|
-
}
|
|
108
|
+
this.ensureSameRootSchema(rootSchema, formData);
|
|
96
109
|
if (get(schema, ID_KEY) === JUNK_OPTION_ID) {
|
|
97
110
|
return false;
|
|
98
111
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"precompiledValidator.js","sourceRoot":"","sources":["../src/precompiledValidator.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,MAAM,YAAY,CAAC;AAC7B,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAKL,aAAa,EACb,MAAM,EACN,cAAc,EAGd,WAAW,EAIX,cAAc,GACf,MAAM,aAAa,CAAC;AAGrB,OAAO,0BAAuD,MAAM,8BAA8B,CAAC;AAEnG;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,wBAAwB;IA8B3C;;;;;;OAMG;IACH,YAAY,WAA+B,EAAE,UAAa,EAAE,SAAqB;QAC/E,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;IACrD,CAAC;IAED;;;;;OAKG;IACH,YAAY,CAAC,MAAS;QACpB,MAAM,GA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AC,CAAC;QACpE,OAAO,0BAA0B,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,eAAe,EAAE,QAAQ,CAAC,CAAC;IAClH,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;YAC1C,OAAO,KAAK,CAAC;SACd;QACD,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAC5C,OAAO,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC;CACF"}
|
package/lib/validator.js
CHANGED
|
@@ -90,9 +90,10 @@ export default class AJV8Validator {
|
|
|
90
90
|
// then rewrite the schema ref's to point to the rootSchema
|
|
91
91
|
// this accounts for the case where schema have references to models
|
|
92
92
|
// that lives in the rootSchema but not in the schema in question.
|
|
93
|
-
if (this.ajv.getSchema(rootSchemaId) === undefined) {
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
// if (this.ajv.getSchema(rootSchemaId) === undefined) {
|
|
94
|
+
// TODO restore the commented out `if` above when the TODO in the `finally` is completed
|
|
95
|
+
this.ajv.addSchema(rootSchema, rootSchemaId);
|
|
96
|
+
// }
|
|
96
97
|
const schemaWithIdRefPrefix = withIdRefPrefix(schema);
|
|
97
98
|
const schemaId = (_b = schemaWithIdRefPrefix[ID_KEY]) !== null && _b !== void 0 ? _b : hashForSchema(schemaWithIdRefPrefix);
|
|
98
99
|
let compiledValidator;
|
package/lib/validator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,MAAM,EAEN,kBAAkB,EAElB,WAAW,EAIX,eAAe,E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AO,CAAC,EAAE;YACV,OAAO,CAAC,IAAI,CAAC,qCAAqC,EAAE,CAAC,CAAC,CAAC;YACvD,OAAO,KAAK,CAAC;SACd;gBAAS;YACR,8HAA8H;YAC9H,kEAAkE;YAClE,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;SACrC;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rjsf/validator-ajv8",
|
|
3
|
-
"version": "5.13.
|
|
3
|
+
"version": "5.13.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -43,22 +43,22 @@
|
|
|
43
43
|
"@rjsf/utils": "^5.12.x"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@babel/core": "^7.22.
|
|
46
|
+
"@babel/core": "^7.22.17",
|
|
47
47
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
48
48
|
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
|
|
49
|
-
"@babel/preset-env": "^7.22.
|
|
50
|
-
"@babel/preset-react": "^7.22.
|
|
51
|
-
"@babel/preset-typescript": "^7.22.
|
|
52
|
-
"@rjsf/utils": "^5.13.
|
|
49
|
+
"@babel/preset-env": "^7.22.15",
|
|
50
|
+
"@babel/preset-react": "^7.22.15",
|
|
51
|
+
"@babel/preset-typescript": "^7.22.15",
|
|
52
|
+
"@rjsf/utils": "^5.13.2",
|
|
53
53
|
"@types/json-schema": "^7.0.12",
|
|
54
|
-
"@types/lodash": "^4.14.
|
|
55
|
-
"babel-jest": "^29.6.
|
|
56
|
-
"esbuild": "^0.18.
|
|
57
|
-
"eslint": "^8.
|
|
58
|
-
"jest": "^29.6.
|
|
59
|
-
"jest-environment-jsdom": "^29.6.
|
|
54
|
+
"@types/lodash": "^4.14.198",
|
|
55
|
+
"babel-jest": "^29.6.4",
|
|
56
|
+
"esbuild": "^0.18.20",
|
|
57
|
+
"eslint": "^8.48.0",
|
|
58
|
+
"jest": "^29.6.4",
|
|
59
|
+
"jest-environment-jsdom": "^29.6.4",
|
|
60
60
|
"rimraf": "^5.0.1",
|
|
61
|
-
"rollup": "^3.
|
|
61
|
+
"rollup": "^3.29.0",
|
|
62
62
|
"typescript": "^4.9.5"
|
|
63
63
|
},
|
|
64
64
|
"publishConfig": {
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
"url": "git+https://github.com/rjsf-team/react-jsonschema-form.git"
|
|
83
83
|
},
|
|
84
84
|
"license": "Apache-2.0",
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "4cfaa984c3343d9cbaabd147c5c24b2c01e28726"
|
|
86
86
|
}
|
|
@@ -83,6 +83,27 @@ export default class AJV8PrecompiledValidator<
|
|
|
83
83
|
return validator;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
/** Ensures that the validator is using the same schema as the root schema used to construct the precompiled
|
|
87
|
+
* validator. It first compares the given `schema` against the root schema and if they aren't the same, then it
|
|
88
|
+
* checks against the resolved root schema, on the chance that a resolved version of the root schema was passed in
|
|
89
|
+
* instead of the raw root schema.
|
|
90
|
+
*
|
|
91
|
+
* @param schema - The schema against which to validate the form data
|
|
92
|
+
* @param [formData] - The form data to validate if any
|
|
93
|
+
*/
|
|
94
|
+
ensureSameRootSchema(schema: S, formData?: T) {
|
|
95
|
+
if (!isEqual(schema, this.rootSchema)) {
|
|
96
|
+
// Resolve the root schema with the passed in form data since that may affect the resolution
|
|
97
|
+
const resolvedRootSchema = retrieveSchema(this, this.rootSchema, this.rootSchema, formData);
|
|
98
|
+
if (!isEqual(schema, resolvedRootSchema)) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
'The schema associated with the precompiled validator differs from the rootSchema provided for validation'
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
|
|
86
107
|
/** Converts an `errorSchema` into a list of `RJSFValidationErrors`
|
|
87
108
|
*
|
|
88
109
|
* @param errorSchema - The `ErrorSchema` instance to convert
|
|
@@ -97,17 +118,12 @@ export default class AJV8PrecompiledValidator<
|
|
|
97
118
|
/** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use
|
|
98
119
|
* by the playground. Returns the `errors` from the validation
|
|
99
120
|
*
|
|
100
|
-
* @param schema - The schema against which to validate the form data
|
|
101
|
-
* @param formData - The form data to validate
|
|
121
|
+
* @param schema - The schema against which to validate the form data
|
|
122
|
+
* @param [formData] - The form data to validate, if any
|
|
102
123
|
* @throws - Error when the schema provided does not match the base schema of the precompiled validator
|
|
103
124
|
*/
|
|
104
125
|
rawValidation<Result = any>(schema: S, formData?: T): RawValidationErrorsType<Result> {
|
|
105
|
-
|
|
106
|
-
if (!isEqual(schema, resolvedRootSchema)) {
|
|
107
|
-
throw new Error(
|
|
108
|
-
'The schema associated with the precompiled schema differs from the schema provided for validation'
|
|
109
|
-
);
|
|
110
|
-
}
|
|
126
|
+
this.ensureSameRootSchema(schema, formData);
|
|
111
127
|
this.mainValidator(formData);
|
|
112
128
|
|
|
113
129
|
if (typeof this.localizer === 'function') {
|
|
@@ -154,11 +170,7 @@ export default class AJV8PrecompiledValidator<
|
|
|
154
170
|
* isn't a precompiled validator function associated with the schema
|
|
155
171
|
*/
|
|
156
172
|
isValid(schema: S, formData: T | undefined, rootSchema: S) {
|
|
157
|
-
|
|
158
|
-
throw new Error(
|
|
159
|
-
'The schema associated with the precompiled validator differs from the rootSchema provided for validation'
|
|
160
|
-
);
|
|
161
|
-
}
|
|
173
|
+
this.ensureSameRootSchema(rootSchema, formData);
|
|
162
174
|
if (get(schema, ID_KEY) === JUNK_OPTION_ID) {
|
|
163
175
|
return false;
|
|
164
176
|
}
|
package/src/validator.ts
CHANGED
|
@@ -134,9 +134,10 @@ export default class AJV8Validator<T = any, S extends StrictRJSFSchema = RJSFSch
|
|
|
134
134
|
// then rewrite the schema ref's to point to the rootSchema
|
|
135
135
|
// this accounts for the case where schema have references to models
|
|
136
136
|
// that lives in the rootSchema but not in the schema in question.
|
|
137
|
-
if (this.ajv.getSchema(rootSchemaId) === undefined) {
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
// if (this.ajv.getSchema(rootSchemaId) === undefined) {
|
|
138
|
+
// TODO restore the commented out `if` above when the TODO in the `finally` is completed
|
|
139
|
+
this.ajv.addSchema(rootSchema, rootSchemaId);
|
|
140
|
+
// }
|
|
140
141
|
const schemaWithIdRefPrefix = withIdRefPrefix<S>(schema) as S;
|
|
141
142
|
const schemaId = schemaWithIdRefPrefix[ID_KEY] ?? hashForSchema(schemaWithIdRefPrefix);
|
|
142
143
|
let compiledValidator: ValidateFunction | undefined;
|