aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/entities.js31
-rw-r--r--common/jsonschema.js7
2 files changed, 25 insertions, 13 deletions
diff --git a/common/entities.js b/common/entities.js
index 41d6e3b..c24999e 100644
--- a/common/entities.js
+++ b/common/entities.js
@@ -117,24 +117,37 @@ function* get_used_files(item)
#EXPORT get_used_files AS get_files
/*
- * Regex to parse URIs like:
+ * Function to parse URIs like:
* https://hydrilla.koszko.org/schemas/api_mapping_description-2.schema.json
*/
-const name_base_re = "(?<name_base>[^/]*)";
-const major_number_re = "(?<major>[1-9][0-9]*)";
+const name_base_re = "([^/]*)";
+const major_number_re = "([1-9][0-9]*)";
const minor_number_re = "(?:[1-9][0-9]*|0)";
const numbers_rest_re = `(?:\\.${minor_number_re})*`;
-const version_re = `(?<ver>${major_number_re}${numbers_rest_re})`;
+const version_re = `(${major_number_re}${numbers_rest_re})`;
const schema_name_re = `${name_base_re}-${version_re}\\.schema\\.json`;
-const haketilo_schema_name_regex = new RegExp(schema_name_re);
-#EXPORT haketilo_schema_name_regex
+const schema_name_regex = new RegExp(schema_name_re);
+
+const schema_name_parts = ["full", "name_base", "version", "major"];
+
+function parse_schema_uri(uri) {
+ const match = schema_name_regex.exec(uri);
+ if (!match)
+ return match;
+
+ const result = {};
+
+ for (let i = 0; i < schema_name_parts.length; i++)
+ result[schema_name_parts[i]] = match[i];
+
+ return result
+}
+#EXPORT parse_schema_uri
/* Extract the number that indicates entity's compatibility mode. */
function get_schema_major_version(instance) {
- const match = haketilo_schema_name_regex.exec(instance.$schema);
-
- return parseInt(match.groups.major);
+ return parseInt(parse_schema_uri(instance.$schema).major);
}
#EXPORT get_schema_major_version
diff --git a/common/jsonschema.js b/common/jsonschema.js
index 9c4a70c..3a82702 100644
--- a/common/jsonschema.js
+++ b/common/jsonschema.js
@@ -57,7 +57,7 @@
#FROM common/jsonschema/scan.js IMPORT SchemaScanResult, scan
-#FROM common/entities.js IMPORT haketilo_schema_name_regex
+#FROM common/entities.js IMPORT parse_schema_uri
#EXPORT scan
#EXPORT SchemaScanResult
@@ -89,9 +89,8 @@ const haketilo_schemas = [
].reduce((ac, s) => Object.assign(ac, {[s.$id]: s}), {});
for (const [$id, schema] of [...Object.entries(haketilo_schemas)]) {
- const match = haketilo_schema_name_regex.exec($id);
- const schema_name =
- `${match.groups.name_base}-${match.groups.major}.schema.json`;
+ const parsed = parse_schema_uri($id);
+ const schema_name = `${parsed.name_base}-${parsed.major}.schema.json`;
haketilo_schemas[schema_name] = schema;
}