Skip to content

Remove ajv-formats-draft2019 #1226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ See the shipped `package.json` for version constraints.
* Validation of JSON on _Node.js_ requires all of:
* [`ajv`](https://www.npmjs.com/package/ajv)
* [`ajv-formats`](https://www.npmjs.com/package/ajv-formats)
* [`ajv-formats-draft2019`](https://www.npmjs.com/package/ajv-formats-draft2019)
* Validation of XML on _Node.js_ requires all of:
* [`libxmljs2`](https://www.npmjs.com/package/libxmljs2)
* the system might need to meet the requirements for [`node-gyp`](https://github.com/TooTallNate/node-gyp#installation), in certain cases.
Expand Down
1 change: 0 additions & 1 deletion docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ See the shipped ``package.json`` for version constraints.
* Validation of JSON on _Node.js_ requires all of:
* `ajv <https://www.npmjs.com/package/ajv>`_
* `ajv-formats <https://www.npmjs.com/package/ajv-formats>`_
* `ajv-formats-draft2019 <https://www.npmjs.com/package/ajv-formats-draft2019>`_
* Validation of XML on _Node.js_ requires all of:
* `libxmljs2 <https://www.npmjs.com/package/libxmljs2>`_
* the system must meet the requirements for `node-gyp <https://github.com/TooTallNate/node-gyp#installation>`_
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
"optionalDependencies": {
"ajv": "^8.12.0",
"ajv-formats": "^3.0.1",
"ajv-formats-draft2019": "^1.6.1",
"libxmljs2": "^0.35",
"xmlbuilder2": "^3.0.2"
},
Expand Down
11 changes: 4 additions & 7 deletions src/_optPlug.node/__jsonValidators/ajv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import { readFile } from 'node:fs/promises'

import Ajv, { type Options as AjvOptions } from 'ajv'
import addFormats from 'ajv-formats'
/* @ts-expect-error TS7016 */
import addFormats2019 from 'ajv-formats-draft2019'

import type { ValidationError } from '../../validation/types'
import type { Functionality, Validator } from '../jsonValidator'
Expand All @@ -34,7 +32,6 @@ const ajvOptions: AjvOptions = Object.freeze({
strictSchema: false,
addUsedSchema: false
})

/** @internal */
export default (async function (schemaPath: string, schemaMap: Record<string, string> = {}): Promise<Validator> {
/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-return -- intended */
Expand All @@ -49,10 +46,10 @@ export default (async function (schemaPath: string, schemaMap: Record<string, st
/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- intended */
const ajv = new Ajv({ ...ajvOptions, schemas })
addFormats(ajv)
/* eslint-disable-next-line @typescript-eslint/no-unsafe-call -- intended */
addFormats2019(ajv, { formats: ['idn-email'] })
// there is just no working implementation for format "iri-reference": see https://github.com/luzlab/ajv-formats-draft2019/issues/22
ajv.addFormat('iri-reference', true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where did the this go?


// Add IDN email format - part of what was previously provided by ajv-formats-draft2019
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a TODO?

// Setting to true to be permissive (IDN emails are valid emails with unicode chars)
ajv.addFormat('idn-email', true)

const validator = ajv.compile(schema)

Expand Down
2 changes: 1 addition & 1 deletion src/_optPlug.node/jsonValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default opWrapper<Functionality>('JsonValidator', [
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-require-imports
-- needed */

['( ajv && ajv-formats && ajv-formats-draft2019 )', () => require('./__jsonValidators/ajv').default]
['( ajv && ajv-formats )', () => require('./__jsonValidators/ajv').default]
// ... add others here, pull-requests welcome!

/* eslint-enable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-require-imports */
Expand Down