synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
107 lines (106 loc) • 2.88 kB
JavaScript
import { isEqual as f } from "lodash-es";
import { parseEntityIdFromSqlStatement as w } from "./SqlFunctions.js";
async function y(r) {
const n = new TextEncoder().encode(r), a = new CompressionStream("gzip"), e = a.writable.getWriter(), s = new Response(a.readable).arrayBuffer();
await e.write(n), await e.close();
const i = await s, o = new Uint8Array(i);
let c = "";
for (let l = 0; l < o.length; l++)
c += String.fromCharCode(o[l]);
return btoa(c);
}
async function p(r) {
const t = atob(r), n = new Uint8Array(t.length);
for (let c = 0; c < t.length; c++)
n[c] = t.charCodeAt(c);
const a = new DecompressionStream("gzip"), e = a.writable.getWriter(), s = new Response(a.readable).arrayBuffer();
await e.write(n), await e.close();
const i = await s;
return new TextDecoder().decode(i);
}
function d(r, t) {
return `${r}${t}`;
}
function m(r, t) {
if (f(r, t))
return null;
const n = {}, a = /* @__PURE__ */ new Set([
...Object.keys(r),
...Object.keys(t)
]);
for (const e of a)
f(r[e], t[e]) || (n[e] = r[e]);
return Object.keys(n).length > 0 ? n : null;
}
function u(r, t) {
return {
...r,
...t
};
}
async function h(r, t, n, a) {
const e = t !== void 0 ? d(r, t) : r, s = new URLSearchParams(window.location.search);
if (n && a) {
const o = m(n, a);
if (o) {
const c = JSON.stringify(o), l = await y(c);
s.set(e, l);
} else
s.delete(e);
} else
s.delete(e);
const i = s.toString();
window.history.replaceState(
window.history.state,
"",
window.location.pathname + (Array.from(s).length > 0 ? `?${i.toString()}` : "")
);
}
async function b(r, t) {
const n = d("qw", r), a = new URLSearchParams(window.location.search).get(
n
);
let e;
if (a)
try {
const o = await p(a), c = JSON.parse(o), l = u(t, c);
l.sql && (e = {
concreteType: "org.sagebionetworks.repo.model.table.QueryBundleRequest",
entityId: w(l.sql),
query: l
});
} catch (o) {
console.error("Failed to parse query diff from URL:", o);
}
const s = d(
"QueryWrapper",
r
), i = new URLSearchParams(
window.location.search
).get(s);
if (i && !e)
try {
const o = JSON.parse(i);
o.sql && (e = {
concreteType: "org.sagebionetworks.repo.model.table.QueryBundleRequest",
entityId: w(o.sql),
query: o
});
} catch (o) {
console.error("Failed to parse legacy query from URL:", o);
}
return e;
}
async function q(r, t, n, a) {
const e = m(n, a);
if (!e)
return r;
const s = JSON.stringify(e), i = await y(s), o = d("qw", t);
return `${r}?${o}=${encodeURIComponent(i)}`;
}
export {
q as generateCompressedQueryURL,
b as getQueryRequestFromLink,
h as updateUrlWithNewSearchParam
};
//# sourceMappingURL=deepLinkingUtils.js.map