Commit 3e6d462b authored by Boris Kocherov's avatar Boris Kocherov

'urn:jio:reference?' url schema supported

parent 59e8ced8
...@@ -5,6 +5,36 @@ ...@@ -5,6 +5,36 @@
"use strict"; "use strict";
var expandSchema; var expandSchema;
function URLwithJio(url, base_url) {
var urn_prefix,
pathname,
fake_prefix = "https://jio_urn_prefix/";
// XXX urn: can any case
if (url.startsWith("urn:jio:reference?")) {
urn_prefix = url.indexOf("?") + 1;
urn_prefix = url.slice(0, urn_prefix);
url = fake_prefix + decodeURIComponent(url.replace(urn_prefix, ""));
}
if (typeof base_url === "string" && base_url.startsWith("urn:jio:reference?")) {
if (!urn_prefix) {
urn_prefix = base_url.indexOf("?") + 1;
urn_prefix = base_url.slice(0, urn_prefix);
}
base_url = fake_prefix + decodeURIComponent(base_url.replace(urn_prefix, ""));
}
url = new URL(url, base_url);
if (urn_prefix) {
pathname = url.pathname.slice(1);
return {
href: urn_prefix + encodeURIComponent(pathname + url.search + url.hash),
origin: urn_prefix,
pathname: encodeURIComponent(pathname),
hash: url.hash
};
}
return url;
}
function decodeJsonPointer(_str) { function decodeJsonPointer(_str) {
// https://tools.ietf.org/html/rfc6901#section-5 // https://tools.ietf.org/html/rfc6901#section-5
return _str.replace(/~1/g, '/').replace(/~0/g, '~'); return _str.replace(/~1/g, '/').replace(/~0/g, '~');
...@@ -87,9 +117,9 @@ ...@@ -87,9 +117,9 @@
base_url = convertToRealWorldSchemaPath(g, path), base_url = convertToRealWorldSchemaPath(g, path),
absolute_url; absolute_url;
if (base_url === "" || base_url.indexOf("#") === 0) { if (base_url === "" || base_url.indexOf("#") === 0) {
absolute_url = new URL(url, base_url_failback); absolute_url = URLwithJio(url, base_url_failback);
} else { } else {
absolute_url = new URL(url, base_url); absolute_url = URLwithJio(url, base_url);
} }
return absolute_url; return absolute_url;
} }
...@@ -154,7 +184,8 @@ ...@@ -154,7 +184,8 @@
url, url,
download_url, download_url,
hash, hash,
schema_url_map; schema_url_map,
queue;
// XXX need use `id` property // XXX need use `id` property
if (!path) { if (!path) {
path = "/"; path = "/";
...@@ -179,7 +210,18 @@ ...@@ -179,7 +210,18 @@
} }
hash = url.hash; hash = url.hash;
url = url.href; url = url.href;
return downloadJSON(download_url) if (download_url.startsWith("urn:jio:")) {
queue = RSVP.Queue()
.push(function () {
return g.downloadJSON(download_url);
});
} else {
queue = RSVP.Queue()
.push(function () {
return downloadJSON(download_url);
});
}
return queue
.push(function (json) { .push(function (json) {
checkCircular(g, path, url); checkCircular(g, path, url);
return resolveLocalReference(json, hash); return resolveLocalReference(json, hash);
...@@ -192,9 +234,9 @@ ...@@ -192,9 +234,9 @@
schema_a = document.createElement("a"), schema_a = document.createElement("a"),
pointed_a = document.createElement("a"); pointed_a = document.createElement("a");
schema_a.setAttribute("href", download_url); schema_a.setAttribute("href", download_url);
schema_a.text = (new URL(download_url)).pathname; schema_a.text = (URLwithJio(download_url)).pathname;
pointed_a.setAttribute("href", url_from_pointed); pointed_a.setAttribute("href", url_from_pointed);
pointed_a.text = (new URL(url_from_pointed)).pathname; pointed_a.text = (URLwithJio(url_from_pointed)).pathname;
g.props.schema_resolve_errors[url_from_pointed] = { g.props.schema_resolve_errors[url_from_pointed] = {
schemaPath: path, schemaPath: path,
message: [ message: [
...@@ -373,6 +415,7 @@ ...@@ -373,6 +415,7 @@
g.props = {}; g.props = {};
g.options = {}; g.options = {};
}) })
.declareAcquiredMethod("downloadJSON", "downloadJSON")
.declareAcquiredMethod("notifyChange", "notifyChange") .declareAcquiredMethod("notifyChange", "notifyChange")
.allowPublicAcquisition("notifyChange", function () { .allowPublicAcquisition("notifyChange", function () {
return this.notifyChange(); return this.notifyChange();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment