import { Draft, JSONError, JSONSchema } from '@squiz/json-schema-library'; import { isMatrixAssetUri } from './utils/matrixAssetValidator'; import { getValidationDataForMatrixUri } from './utils/getValidationDataForMatrixUri'; export const customFormatValidators: Record< string, (draft: Draft, schema: JSONSchema, value: unknown, pointer: string) => undefined | JSONError | JSONError[] > = { 'matrix-asset-uri': (core, schema, value, pointer): JSONError[] | undefined => { const errors: JSONError[] = []; if (isMatrixAssetUri(value) === false) { if (typeof value !== 'string') { const error: JSONError = { name: 'typeError', code: 'type-error', type: 'error', message: `Expected matrix-asset-uri (${value}) in \`${pointer}\` to be of type string`, data: { expected: 'string', pointer: pointer, received: typeof value, value: value }, }; return [error]; } const validationData = getValidationDataForMatrixUri(value); const error: JSONError = { name: 'matrixAssetUriError', code: 'format-error', type: 'error', message: `Value matrix-asset-uri (${value}) in \`${pointer}\` is not a valid matrix asset uri`, data: { pointer: pointer, value: value, errors: validationData }, }; return [error]; } return errors.length > 0 ? errors : undefined; }, };