From ba6487fe7bd39a15a9246714ddbaa05dff2c3424 Mon Sep 17 00:00:00 2001 From: Jakob Voss Date: Fri, 27 Oct 2023 07:32:02 +0200 Subject: [PATCH 1/2] Remove unused code --- lib/validate.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/validate.js b/lib/validate.js index 9dd20fc..6ac9fe9 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -6,7 +6,6 @@ export class Validator { constructor(schema, options={}) { this.codelists = schema.codelists || {} this.schedule = new FieldSchedule(schema) - this.deprecated = new FieldSchedule({ ...schema, fields: schema["deprecated-fields"] || {} }) this.options = options } @@ -16,7 +15,6 @@ export class Validator { const { schedule } = this const visitor = new ScheduleVisitor(schedule) - // const deprecatedVisitor = new ScheduleVisitor(deprecated) const errors = [] for (let field of record) { @@ -35,7 +33,6 @@ export class Validator { ? {message: `Unknown field '${key}/${occurrence}'.`, key, occurrence} : {message: `Unknown field '${key}'.`, key}) } - // TODO: support deprecated-fields } const missing = visitor.missing().map(id => ({ From b3af9c47629c81e9a6626b095b2f1edf36294b07 Mon Sep 17 00:00:00 2001 From: Jakob Voss Date: Tue, 28 Nov 2023 08:40:11 +0100 Subject: [PATCH 2/2] Remove support of deprecated elements --- README.md | 1 - lib/validate.js | 18 +----------------- test/suite/codes.json | 19 +++++++------------ 3 files changed, 8 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index e17ec63..5a7beb6 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,6 @@ An empty string schema argument uses the empty schema. Combining -n and -v emits parsed records. Validation options (separable with any of [ ,|+]): ignore_unknown_fields - allow_deprecated ignore_subfields ignore_unknown_subfields ignore_values diff --git a/lib/validate.js b/lib/validate.js index 6ac9fe9..1b1af5d 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -48,7 +48,6 @@ export class Validator { Validator.options = { ignore_unknown_fields: true, ignore_subfields: true, - // allow_deprecated: true, ignore_unknown_subfields: true, // check_subfield_order: true, ignore_values: true, @@ -133,7 +132,7 @@ export const validatePattern = (value, pattern) => { // See https://format.gbv.de/schema/avram/specification#validation-with-codelist export const validateCode = (value, definition, options = {}) => { - const { ignore_codes, ignore_unknown_codelists, allow_deprecated, codelists } = options + const { ignore_codes, ignore_unknown_codelists, codelists } = options var { codes } = definition if (ignore_codes || !codes) return [] @@ -151,21 +150,6 @@ export const validateCode = (value, definition, options = {}) => { // value found as code if (value in codes) return [] - // maybe the value is a deprecated code - if (allow_deprecated) { - codes = definition["deprecated-codes"] - if (typeof codes === "string") { - // This code is duplicated above, maybe merge into function? - if (codelists && codes in codelists) { - codes = codelists[codes] - } else { - return ignore_unknown_codelists ? [] : - [{ message: `Unknown codelist '${codes}'.`, value: codes }] - } - } - if (codes && value in codes) return [] - } - // TODO: we may include information about referenced codelist return [{message: `Value '${value}' is not defined in codelist.`, value}] } diff --git a/test/suite/codes.json b/test/suite/codes.json index 8e3e3d2..183ede3 100644 --- a/test/suite/codes.json +++ b/test/suite/codes.json @@ -7,12 +7,10 @@ }, "fields": { "lang": { - "codes": "languages", - "deprecated-codes": { "deu": { } } + "codes": "languages" }, "bool": { - "codes": { "yes": {}, "no": {} }, - "deprecated-codes": "not-found" + "codes": { "yes": {}, "no": {} } }, "wtf": { "codes": "xy" @@ -45,18 +43,15 @@ ], "options": ["ignore_codes"] },{ - "description": "allow_deprecated", - "record": [ - { "key": "lang", "value": "deu" } - ], - "options": ["allow_deprecated"] - },{ - "description": "ignore_unknown_codelists & allow_deprecated", + "description": "ignore_unknown_codelists", "record": [ { "key": "bool", "value": "y" }, { "key": "wtf", "value": "xy" } ], - "options": ["ignore_unknown_codelists", "allow_deprecated"] + "options": ["ignore_unknown_codelists"], + "errors": [ + { "message": "Value 'y' is not defined in codelist.", "value": "y" } + ] } ] }