@@ -2,9 +2,9 @@ import { ErrorObject } from 'ajv'
22
33type ErrorQueryFind = {
44 [ key : string ] : string | undefined
5- instancePath : string
5+ instancePath ? : string | undefined
66 message ?: string | undefined
7- schemaPath : string
7+ schemaPath ? : string | undefined
88}
99type ErrorQueryReplace = {
1010 message : string
@@ -17,13 +17,14 @@ export type ErrorQuery = {
1717export const byError = ( errors : ErrorObject [ ] ) => {
1818 return ( query : ErrorQuery ) => {
1919 const matches = ( error : ErrorObject ) => {
20- if ( query . find . instancePath !== error . instancePath ) {
20+ const keys = Object . keys ( query . find )
21+ if ( keys . includes ( 'instancePath' ) && query . find . instancePath !== error . instancePath ) {
2122 return false
2223 }
23- if ( query . find . schemaPath !== error . schemaPath ) {
24+ if ( keys . includes ( 'schemaPath' ) && query . find . schemaPath !== error . schemaPath ) {
2425 return false
2526 }
26- if ( Object . keys ( query . find ) . includes ( 'message' ) && query . find . message !== error . message ) {
27+ if ( keys . includes ( 'message' ) && query . find . message !== error . message ) {
2728 return false
2829 }
2930 return true
@@ -73,6 +74,57 @@ export const emailQueries = (index: number) => {
7374 } ] as ErrorQuery [ ]
7475}
7576
77+ export const identifierValueQueries = ( index : number , typeIndex : number ) => {
78+ return [ [
79+ {
80+ find : {
81+ instancePath : `/identifiers/${ index } /value` ,
82+ schemaPath : '#/definitions/doi/pattern'
83+ } ,
84+ replace : {
85+ message : 'e.g. \'10.5281/zenodo.1003149\' or \'10.7717/peerj-cs.86\'. Does not include the resolver URL.'
86+ }
87+ } ,
88+ {
89+ find : {
90+ instancePath : `/identifiers/${ index } /value` ,
91+ schemaPath : '#/definitions/url/pattern'
92+ } ,
93+ replace : {
94+ message : 'e.g. \'https://www.example.com\' (http, ftp, sftp hyperlinks are also supported)'
95+ }
96+ } ,
97+ {
98+ find : {
99+ instancePath : `/identifiers/${ index } /value` ,
100+ schemaPath : '#/definitions/swh-identifier/pattern'
101+ } ,
102+ replace : {
103+ message : 'e.g. \'swh:1:rev:309cf2674ee7a0749978cf8265ab91a60aea0f7d\'. Besides \'rev\', other allowed values are: \'snp\', \'rel\', \'dir\', and \'cnt\'.'
104+ }
105+ } ,
106+ {
107+ find : {
108+ instancePath : `/identifiers/${ index } /value` ,
109+ schemaPath : '#/anyOf/3/properties/value/minLength'
110+ } ,
111+ replace : {
112+ message : 'Zero-length identifier values are not allowed. Please type an identifier value or remove the identifier entirely.'
113+ }
114+ }
115+ ] [ typeIndex ] ] as ErrorQuery [ ]
116+ }
117+
118+ export const identifiersQueries : ErrorQuery [ ] = [ {
119+ find : {
120+ instancePath : '/identifiers' ,
121+ schemaPath : '#/properties/identifiers/uniqueItems'
122+ } ,
123+ replace : {
124+ message : 'There are duplicate identifiers.'
125+ }
126+ } ]
127+
76128export const keywordQueries = ( index : number ) => {
77129 return [ {
78130 find : {
0 commit comments