summaryrefslogtreecommitdiff
path: root/ext/js/background
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-05-22 15:45:20 -0400
committerGitHub <noreply@github.com>2021-05-22 15:45:20 -0400
commitd16739a83a20e1729e08dbcbbc155be15972d146 (patch)
treef7c12fa946a688750365ecf0f66227fcad4f927d /ext/js/background
parentb48052ff320f1a68aac317158c4c757a70b14f04 (diff)
Json schema validation improvements (#1697)
* Create new JsonSchema class * Add proxy handler * Update tests * Update validation scripts * Update backend * Update audio downloader * Update options util * Update dictionary importer * Update json schema file reference * Remove old json-schema.js * Rename new json-schema.js * Update file names * Rename class
Diffstat (limited to 'ext/js/background')
-rw-r--r--ext/js/background/backend.js5
-rw-r--r--ext/js/background/profile-conditions-util.js12
2 files changed, 10 insertions, 7 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js
index e94ad065..2368b5d0 100644
--- a/ext/js/background/backend.js
+++ b/ext/js/background/backend.js
@@ -24,7 +24,6 @@
* DictionaryDatabase
* Environment
* JapaneseUtil
- * JsonSchemaValidator
* Mecab
* MediaUtil
* ObjectPropertyAccessor
@@ -58,7 +57,6 @@ class Backend {
clipboardReader: this._clipboardReader
});
this._options = null;
- this._profileConditionsSchemaValidator = new JsonSchemaValidator();
this._profileConditionsSchemaCache = [];
this._profileConditionsUtil = new ProfileConditionsUtil();
this._defaultAnkiFieldTemplates = null;
@@ -1018,7 +1016,7 @@ class Backend {
this._profileConditionsSchemaCache.push(schema);
}
- if (conditionGroups.length > 0 && this._profileConditionsSchemaValidator.isValid(optionsContext, schema)) {
+ if (conditionGroups.length > 0 && schema.isValid(optionsContext)) {
return profile;
}
++index;
@@ -1029,7 +1027,6 @@ class Backend {
_clearProfileConditionsSchemaCache() {
this._profileConditionsSchemaCache = [];
- this._profileConditionsSchemaValidator.clearCache();
}
_checkLastError() {
diff --git a/ext/js/background/profile-conditions-util.js b/ext/js/background/profile-conditions-util.js
index dcd60796..2de25420 100644
--- a/ext/js/background/profile-conditions-util.js
+++ b/ext/js/background/profile-conditions-util.js
@@ -15,6 +15,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+/* global
+ * JsonSchema
+ */
+
/**
* Utility class to help processing profile conditions.
*/
@@ -109,11 +113,13 @@ class ProfileConditionsUtil {
default: anyOf.push({allOf}); break;
}
}
+ let schema;
switch (anyOf.length) {
- case 0: return {};
- case 1: return anyOf[0];
- default: return {anyOf};
+ case 0: schema = {}; break;
+ case 1: schema = anyOf[0]; break;
+ default: schema = {anyOf}; break;
}
+ return new JsonSchema(schema);
}
/**