Comparing version 0.6.6 to 0.6.7
1063
dist/cirql.js
var Je = Object.defineProperty; | ||
var ze = (t, e, n) => e in t ? Je(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n; | ||
var j = (t, e, n) => (ze(t, typeof e != "symbol" ? e + "" : e, n), n), qe = (t, e, n) => { | ||
if (!e.has(t)) | ||
var ze = (e, t, n) => t in e ? Je(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n; | ||
var j = (e, t, n) => (ze(e, typeof t != "symbol" ? t + "" : t, n), n), Se = (e, t, n) => { | ||
if (!t.has(e)) | ||
throw TypeError("Cannot " + n); | ||
}; | ||
var r = (t, e, n) => (qe(t, e, "read from private field"), n ? n.call(t) : e.get(t)), p = (t, e, n) => { | ||
if (e.has(t)) | ||
var r = (e, t, n) => (Se(e, t, "read from private field"), n ? n.call(e) : t.get(e)), p = (e, t, n) => { | ||
if (t.has(e)) | ||
throw TypeError("Cannot add the same private member more than once"); | ||
e instanceof WeakSet ? e.add(t) : e.set(t, n); | ||
}, N = (t, e, n, i) => (qe(t, e, "write to private field"), i ? i.call(t, n) : e.set(t, n), n), Ie = (t, e, n, i) => ({ | ||
t instanceof WeakSet ? t.add(e) : t.set(e, n); | ||
}, N = (e, t, n, i) => (Se(e, t, "write to private field"), i ? i.call(e, n) : t.set(e, n), n), Ie = (e, t, n, i) => ({ | ||
set _(s) { | ||
N(t, e, s, n); | ||
N(e, t, s, n); | ||
}, | ||
get _() { | ||
return r(t, e, i); | ||
return r(e, t, i); | ||
} | ||
}), E = (t, e, n) => (qe(t, e, "access private method"), n); | ||
}), E = (e, t, n) => (Se(e, t, "access private method"), n); | ||
import Be from "isomorphic-ws"; | ||
@@ -36,3 +36,3 @@ import { z as q } from "zod"; | ||
} | ||
const Ye = (t) => t.errors.map((n) => `- @${n.path.join(".")}: ${n.message}`).join(` | ||
const Ye = (e) => e.errors.map((n) => `- @${n.path.join(".")}: ${n.message}`).join(` | ||
`); | ||
@@ -70,51 +70,51 @@ class M extends Error { | ||
} | ||
class Se extends M { | ||
constructor(e) { | ||
super(e, "auth_failure"); | ||
class Re extends M { | ||
constructor(t) { | ||
super(t, "auth_failure"); | ||
} | ||
} | ||
const U = Symbol("Query Raw"); | ||
function a(t) { | ||
function o(e) { | ||
return { | ||
[U]: t | ||
[U]: e | ||
}; | ||
} | ||
function gt(t) { | ||
return a(`$${t}`); | ||
function Rt(e) { | ||
return o(`$${e}`); | ||
} | ||
function Ke(t) { | ||
return a(`type::bool(${o(t)})`); | ||
function Ke(e) { | ||
return o(`type::bool(${u(e)})`); | ||
} | ||
function We(t) { | ||
return a(`type::datetime(${o(t)})`); | ||
function We(e) { | ||
return o(`type::datetime(${u(e)})`); | ||
} | ||
function Xe(t) { | ||
return a(`type::decimal(${o(t)})`); | ||
function Xe(e) { | ||
return o(`type::decimal(${u(e)})`); | ||
} | ||
function _e(t) { | ||
return a(`type::duration(${o(t)})`); | ||
function _e(e) { | ||
return o(`type::duration(${u(e)})`); | ||
} | ||
function et(t) { | ||
return a(`type::float(${o(t)})`); | ||
function et(e) { | ||
return o(`type::float(${u(e)})`); | ||
} | ||
function tt(t) { | ||
return a(`type::int(${o(t)})`); | ||
function tt(e) { | ||
return o(`type::int(${u(e)})`); | ||
} | ||
function nt(t) { | ||
return a(`type::number(${o(t)})`); | ||
function nt(e) { | ||
return o(`type::number(${u(e)})`); | ||
} | ||
function rt(t, e) { | ||
return a(e ? `type::point(${o(t)}, ${o(e)})` : `type::point(${o(t)})`); | ||
function rt(e, t) { | ||
return o(t ? `type::point(${u(e)}, ${u(t)})` : `type::point(${u(e)})`); | ||
} | ||
function it(t) { | ||
return a(`type::regex(${o(t)})`); | ||
function it(e) { | ||
return o(`type::regex(${u(e)})`); | ||
} | ||
function st(t) { | ||
return a(`type::string(${o(t)})`); | ||
function st(e) { | ||
return o(`type::string(${u(e)})`); | ||
} | ||
function ot(t) { | ||
return a(`type::table(${o(t)})`); | ||
function ot(e) { | ||
return o(`type::table(${u(e)})`); | ||
} | ||
function ut(t, e) { | ||
return a(`type::thing(${o(t)}, ${o(e)})`); | ||
function ut(e, t) { | ||
return o(`type::thing(${u(e)}, ${u(t)})`); | ||
} | ||
@@ -135,43 +135,43 @@ const Ue = { | ||
}, Le = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | ||
function at(t) { | ||
let e = ""; | ||
function at(e) { | ||
let t = ""; | ||
for (let n = 0; n < 7; n++) | ||
e += Le.charAt(Math.floor(Math.random() * Le.length)); | ||
return t ? `${e}_${t}` : e; | ||
t += Le.charAt(Math.floor(Math.random() * Le.length)); | ||
return e ? `${t}_${e}` : t; | ||
} | ||
function le(t, e) { | ||
return `type::thing(${JSON.stringify(t)}, ${JSON.stringify(e)})`; | ||
function le(e, t) { | ||
return `type::thing(${JSON.stringify(e)}, ${JSON.stringify(t)})`; | ||
} | ||
function he(t) { | ||
return t.fromTable ? Ue.thing(t.fromTable, t.fromId) : a(o(t.fromId)); | ||
function he(e) { | ||
return e.fromTable ? Ue.thing(e.fromTable, e.fromId) : o(u(e.fromId)); | ||
} | ||
function fe(t) { | ||
return t.toTable ? Ue.thing(t.toTable, t.toId) : a(o(t.toId)); | ||
function fe(e) { | ||
return e.toTable ? Ue.thing(e.toTable, e.toId) : o(u(e.toId)); | ||
} | ||
function ve(t) { | ||
return typeof t == "object" && !!t[U]; | ||
function qe(e) { | ||
return typeof e == "object" && e !== null && !!e[U]; | ||
} | ||
function xe(t) { | ||
return typeof t == "object" && "toQuery" in t; | ||
function ke(e) { | ||
return typeof e == "object" && "toQuery" in e; | ||
} | ||
function de(...t) { | ||
return t.some((e) => typeof e == "string" && e.includes(",")); | ||
function de(...e) { | ||
return e.some((t) => typeof t == "string" && t.includes(",")); | ||
} | ||
function o(t) { | ||
if (t === void 0) | ||
function u(e) { | ||
if (e === void 0) | ||
throw new Error("Cannot use undefined value"); | ||
return ve(t) ? t[U] : xe(t) ? `(${t.toQuery()})` : t instanceof Date ? JSON.stringify(t.toISOString()) : t === null ? "NONE" : JSON.stringify(t); | ||
return qe(e) ? e[U] : ke(e) ? `(${e.toQuery()})` : e instanceof Date ? JSON.stringify(e.toISOString()) : e === null ? "NONE" : JSON.stringify(e); | ||
} | ||
function V(t, e) { | ||
if (t === void 0) | ||
function V(e, t) { | ||
if (e === void 0) | ||
throw new Error("Cannot use undefined value"); | ||
return ve(t) ? e ? `(${t[U]})` : t[U] : xe(t) ? `(${t.toQuery()})` : t instanceof Date ? t.toISOString() : t === null ? "NONE" : t; | ||
return qe(e) ? t ? `(${e[U]})` : e[U] : ke(e) ? `(${e.toQuery()})` : e instanceof Date ? e.toISOString() : e === null ? "NONE" : e; | ||
} | ||
function ct(t) { | ||
const e = new URL("rpc", t.connection.endpoint.replace("http", "ws")), n = setInterval(() => u("ping"), 3e4), i = new Be(e), s = /* @__PURE__ */ new Map(); | ||
function ct(e) { | ||
const t = new URL("rpc", e.connection.endpoint.replace("http", "ws")), n = setInterval(() => a("ping"), 3e4), i = new Be(t), s = /* @__PURE__ */ new Map(); | ||
let l = !1; | ||
const u = (h, c = []) => { | ||
const a = (h, c = []) => { | ||
const C = at(); | ||
return new Promise((v, A) => { | ||
s.set(C, [v, A]), i.send(JSON.stringify({ | ||
return new Promise((v, O) => { | ||
s.set(C, [v, O]), i.send(JSON.stringify({ | ||
id: C, | ||
@@ -181,3 +181,3 @@ method: h, | ||
})), setTimeout(() => { | ||
s.delete(C) && A(new Error("Request timed out")); | ||
s.delete(C) && O(new Error("Request timed out")); | ||
}, 5e3); | ||
@@ -187,22 +187,22 @@ }); | ||
var C; | ||
clearInterval(n), (C = t.onDisconnect) == null || C.call(t, h, c); | ||
}, g = () => { | ||
clearInterval(n), (C = e.onDisconnect) == null || C.call(e, h, c); | ||
}, y = () => { | ||
l = !0, i.close(), f(-1, "connection terminated"); | ||
}, w = async (h, c) => u("query", c ? [h, c] : [h]), d = async (h) => { | ||
}, w = async (h, c) => a("query", c ? [h, c] : [h]), d = async (h) => { | ||
try { | ||
return "token" in h ? (await u("authenticate", [h.token]), h.token) : await u("signin", [h]); | ||
return "token" in h ? (await a("authenticate", [h.token]), h.token) : await a("signin", [h]); | ||
} catch (c) { | ||
throw new Se("Authentication failed: " + (c.message || "unknown error")); | ||
throw new Re("Authentication failed: " + (c.message || "unknown error")); | ||
} | ||
}, m = async (h) => { | ||
try { | ||
return await u("signup", [h]); | ||
return await a("signup", [h]); | ||
} catch (c) { | ||
throw new Se("Registration failed: " + (c.message || "unknown error")); | ||
throw new Re("Registration failed: " + (c.message || "unknown error")); | ||
} | ||
}, x = async () => { | ||
}, k = async () => { | ||
try { | ||
await u("invalidate"); | ||
await a("invalidate"); | ||
} catch (h) { | ||
throw new Se("Sign out failed: " + (h.message || "unknown error")); | ||
throw new Re("Sign out failed: " + (h.message || "unknown error")); | ||
} | ||
@@ -212,8 +212,8 @@ }; | ||
var C; | ||
const { namespace: h, database: c } = t.connection; | ||
t.credentials && d(t.credentials), h && c && u("use", [h, c]), (C = t.onConnect) == null || C.call(t); | ||
const { namespace: h, database: c } = e.connection; | ||
e.credentials && d(e.credentials), h && c && a("use", [h, c]), (C = e.onConnect) == null || C.call(e); | ||
}), i.addEventListener("close", (h) => { | ||
l || f(h.code, h.reason); | ||
}), i.addEventListener("message", (h) => { | ||
const { id: c, result: C, method: v, error: A } = JSON.parse(h.data); | ||
const { id: c, result: C, method: v, error: O } = JSON.parse(h.data); | ||
if (v !== "notify") | ||
@@ -224,17 +224,17 @@ if (!s.has(c)) | ||
const [P, G] = s.get(c); | ||
s.delete(c), A ? G(A) : P(C); | ||
s.delete(c), O ? G(O) : P(C); | ||
} | ||
}), i.addEventListener("error", (h) => { | ||
var c; | ||
(c = t.onError) == null || c.call(t, h.error); | ||
(c = e.onError) == null || c.call(e, h.error); | ||
}), { | ||
close: g, | ||
close: y, | ||
query: w, | ||
signIn: d, | ||
signUp: m, | ||
signOut: x | ||
signOut: k | ||
}; | ||
} | ||
var H, ue, Re, $e, Pe, Ee, Qe; | ||
class ke extends EventTarget { | ||
var H, ue, Ce, $e, Pe, Ee, Qe; | ||
class xe extends EventTarget { | ||
constructor(n) { | ||
@@ -264,3 +264,3 @@ super(); | ||
async batch(...n) { | ||
return E(this, ue, Re).call(this, { | ||
return E(this, ue, Ce).call(this, { | ||
queries: n, | ||
@@ -279,3 +279,3 @@ prefix: "", | ||
async transaction(...n) { | ||
return E(this, ue, Re).call(this, { | ||
return E(this, ue, Ce).call(this, { | ||
queries: n, | ||
@@ -287,4 +287,4 @@ prefix: "BEGIN TRANSACTION", | ||
} | ||
H = new WeakMap(), ue = new WeakSet(), Re = async function(n) { | ||
var g; | ||
H = new WeakMap(), ue = new WeakSet(), Ce = async function(n) { | ||
var y; | ||
if (!r(this, H).onRequest()) | ||
@@ -294,3 +294,3 @@ throw new M("There is no active connection to the database", "no_connection"); | ||
return []; | ||
const i = E(this, Ee, Qe).call(this, n), s = E(this, $e, Pe).call(this, n), l = [], u = []; | ||
const i = E(this, Ee, Qe).call(this, n), s = E(this, $e, Pe).call(this, n), l = [], a = []; | ||
r(this, H).onLog(s, i); | ||
@@ -307,13 +307,13 @@ const f = await r(this, H).onQuery(s, i); | ||
for (let w = 0; w < f.length; w++) { | ||
const { result: d } = f[w], { query: m, schema: x, validate: h } = n.queries[w], c = m._quantity; | ||
const { result: d } = f[w], { query: m, schema: k, validate: h } = n.queries[w], c = m._quantity; | ||
if (c == "zero") { | ||
u.push(void 0); | ||
a.push(void 0); | ||
continue; | ||
} | ||
const C = ((g = m._transform) == null ? void 0 : g.call(m, d)) ?? d, v = Array.isArray(C) ? C : [C]; | ||
let A; | ||
const C = ((y = m._transform) == null ? void 0 : y.call(m, d)) ?? d, v = Array.isArray(C) ? C : [C]; | ||
let O; | ||
if (h === !1) | ||
A = v; | ||
O = v; | ||
else { | ||
const P = m._schema || x; | ||
const P = m._schema || k; | ||
if (!P) | ||
@@ -324,19 +324,19 @@ throw new M(`No schema provided for query ${w + 1}`, "invalid_request"); | ||
throw new Ve(`Query ${w + 1} failed to parse`, G.error); | ||
A = G.data; | ||
O = G.data; | ||
} | ||
if (c == "one" && A.length === 0) { | ||
if (c == "one" && O.length === 0) { | ||
if (m._fallback === void 0) | ||
throw new M(`Query ${w + 1} expected at least one result but got ${A.length}`, "invalid_response"); | ||
u.push(m._fallback); | ||
throw new M(`Query ${w + 1} expected at least one result but got ${O.length}`, "invalid_response"); | ||
a.push(m._fallback); | ||
continue; | ||
} | ||
if (c == "one" || c == "maybe") { | ||
if (A.length > 1) | ||
throw new M(`Query ${w + 1} expected at most one result but got ${A.length}`, "invalid_response"); | ||
u.push(A[0] || null); | ||
if (O.length > 1) | ||
throw new M(`Query ${w + 1} expected at most one result but got ${O.length}`, "invalid_response"); | ||
a.push(O[0] || null); | ||
continue; | ||
} | ||
u.push(A); | ||
a.push(O); | ||
} | ||
return u; | ||
return a; | ||
}, $e = new WeakSet(), Pe = function(n) { | ||
@@ -349,6 +349,6 @@ let i = n.queries.map((s) => s.query.toQuery()); | ||
for (const s of n.queries) | ||
for (const [l, u] of Object.entries(s.params || {})) { | ||
for (const [l, a] of Object.entries(s.params || {})) { | ||
if (l in i) | ||
throw new M(`The parameter "${l}" was defined multiple times`, "invalid_query"); | ||
i[l] = u; | ||
i[l] = a; | ||
} | ||
@@ -358,3 +358,3 @@ return i; | ||
var Z, D, J, K, W; | ||
class mt extends ke { | ||
class Ct extends xe { | ||
constructor(n) { | ||
@@ -444,3 +444,3 @@ super({ | ||
var be, De; | ||
class $t extends ke { | ||
class Tt extends xe { | ||
constructor(n) { | ||
@@ -473,11 +473,11 @@ super({ | ||
be = new WeakSet(), De = async function(n, i) { | ||
const { endpoint: s, namespace: l, database: u } = this.options.connection, { user: f, pass: g, DB: w, NS: d, SC: m, token: x } = this.options.credentials, h = new URLSearchParams(), c = new URL("sql", s); | ||
if (!f && !g && !x) | ||
const { endpoint: s, namespace: l, database: a } = this.options.connection, { user: f, pass: y, DB: w, NS: d, SC: m, token: k } = this.options.credentials, h = new URLSearchParams(), c = new URL("sql", s); | ||
if (!f && !y && !k) | ||
throw new M("Missing username & password or token", "invalid_request"); | ||
const v = { | ||
"User-Agent": "Cirql", | ||
Authorization: x ? `Bearer ${x}` : `Basic ${btoa(`${f}:${g}`)}`, | ||
Authorization: k ? `Bearer ${k}` : `Basic ${btoa(`${f}:${y}`)}`, | ||
Accept: "application/json" | ||
}; | ||
return (d || l) && (v.NS = d || l), (w || u) && (v.DB = w || u), m && (v.SC = m), Object.entries(i).forEach(([P, G]) => { | ||
return (d || l) && (v.NS = d || l), (w || a) && (v.DB = w || a), m && (v.SC = m), Object.entries(i).forEach(([P, G]) => { | ||
h.set(P, G); | ||
@@ -490,42 +490,42 @@ }), await fetch(`${c}?${h}`, { | ||
}; | ||
function Fe(t) { | ||
const e = []; | ||
function Fe(e) { | ||
const t = []; | ||
function n(i, s) { | ||
Object.entries(i).forEach(([l, u]) => { | ||
if (u !== void 0) | ||
if (typeof u == "object" && !Array.isArray(u) && !(u instanceof Date)) { | ||
const f = u[U]; | ||
f ? e.push(`${s}${l} ${f}`) : n(u, `${s}${l}.`); | ||
Object.entries(i).forEach(([l, a]) => { | ||
if (a !== void 0) | ||
if (qe(a)) { | ||
const f = a[U]; | ||
f ? t.push(`${s}${l} ${f}`) : n(a, `${s}${l}.`); | ||
} else | ||
e.push(`${s}${l} = ${u === null ? "NONE" : JSON.stringify(u)}`); | ||
t.push(`${s}${l} = ${a === null ? "NONE" : JSON.stringify(a)}`); | ||
}); | ||
} | ||
return n(t, ""), e.join(", "); | ||
return n(e, ""), t.join(", "); | ||
} | ||
function k(t) { | ||
const e = Object.keys(t), n = []; | ||
for (const i of e) | ||
function x(e) { | ||
const t = Object.keys(e), n = []; | ||
for (const i of t) | ||
if (i === "OR" || i === "AND") { | ||
const s = t[i], l = []; | ||
const s = e[i], l = []; | ||
if (s === void 0) | ||
throw new M("Received expected undefined property in where clause", "invalid_request"); | ||
for (const u of s) | ||
l.push(`(${k(u)})`); | ||
for (const a of s) | ||
l.push(`(${x(a)})`); | ||
n.push(`(${l.join(` ${i} `)})`); | ||
} else if (i == "QUERY") { | ||
const [s, l] = t[i]; | ||
const [s, l] = e[i]; | ||
n.push(`(${s.toQuery()}) ${l[U]}`); | ||
} else { | ||
const s = t[i]; | ||
ve(s) ? n.push(`${i} ${s[U]}`) : n.push(`${i} = ${JSON.stringify(s)}`); | ||
const s = e[i]; | ||
qe(s) ? n.push(`${i} ${s[U]}`) : n.push(`${i} = ${JSON.stringify(s)}`); | ||
} | ||
return n.join(" AND "); | ||
} | ||
var S, ae, Ce, X, we; | ||
var S, ae, Te, X, we; | ||
const I = class { | ||
constructor(e) { | ||
constructor(t) { | ||
p(this, ae); | ||
p(this, X); | ||
p(this, S, void 0); | ||
N(this, S, e); | ||
N(this, S, t); | ||
} | ||
@@ -548,6 +548,6 @@ get _schema() { | ||
*/ | ||
with(e) { | ||
with(t) { | ||
return new I({ | ||
...r(this, S), | ||
schema: e | ||
schema: t | ||
}); | ||
@@ -563,4 +563,4 @@ } | ||
*/ | ||
withSchema(e) { | ||
return this.with(q.object(e)); | ||
withSchema(t) { | ||
return this.with(q.object(t)); | ||
} | ||
@@ -584,3 +584,3 @@ /** | ||
*/ | ||
set(e, n) { | ||
set(t, n) { | ||
if (E(this, X, we).call(this)) | ||
@@ -592,3 +592,3 @@ throw new b("Cannot set field when content is set"); | ||
...r(this, S).setFields, | ||
[e]: n | ||
[t]: n | ||
} | ||
@@ -605,3 +605,3 @@ }); | ||
*/ | ||
setAll(e) { | ||
setAll(t) { | ||
if (E(this, X, we).call(this)) | ||
@@ -613,3 +613,3 @@ throw new b("Cannot set fields when content is set"); | ||
...r(this, S).setFields, | ||
...e | ||
...t | ||
} | ||
@@ -627,8 +627,8 @@ }); | ||
*/ | ||
content(e) { | ||
if (E(this, ae, Ce).call(this)) | ||
content(t) { | ||
if (E(this, ae, Te).call(this)) | ||
throw new b("Cannot set content when fields are set"); | ||
return new I({ | ||
...r(this, S), | ||
content: e | ||
content: t | ||
}); | ||
@@ -642,6 +642,6 @@ } | ||
*/ | ||
return(e) { | ||
return(t) { | ||
return new I({ | ||
...r(this, S), | ||
returnMode: e | ||
returnMode: t | ||
}); | ||
@@ -655,7 +655,7 @@ } | ||
*/ | ||
returnFields(...e) { | ||
returnFields(...t) { | ||
return new I({ | ||
...r(this, S), | ||
returnMode: "fields", | ||
returnFields: e | ||
returnFields: t | ||
}); | ||
@@ -669,6 +669,6 @@ } | ||
*/ | ||
timeout(e) { | ||
timeout(t) { | ||
return new I({ | ||
...r(this, S), | ||
timeout: e | ||
timeout: t | ||
}); | ||
@@ -689,3 +689,3 @@ } | ||
const { | ||
targets: e, | ||
targets: t, | ||
content: n, | ||
@@ -695,18 +695,18 @@ setFields: i, | ||
returnFields: l, | ||
timeout: u, | ||
timeout: a, | ||
parallel: f | ||
} = r(this, S); | ||
if (!e) | ||
if (!t) | ||
throw new Error("No targets specified"); | ||
let g = `CREATE ${e}`; | ||
if (E(this, ae, Ce).call(this)) { | ||
let y = `CREATE ${t}`; | ||
if (E(this, ae, Te).call(this)) { | ||
const w = Fe(i); | ||
w && (g += ` SET ${w}`); | ||
w && (y += ` SET ${w}`); | ||
} else | ||
E(this, X, we).call(this) && (g += ` CONTENT ${JSON.stringify(n)}`); | ||
return s === "fields" ? g += ` RETURN ${l.join(", ")}` : s && (g += ` RETURN ${s.toUpperCase()}`), u && (g += ` TIMEOUT ${u}s`), f && (g += " PARALLEL"), g; | ||
E(this, X, we).call(this) && (y += ` CONTENT ${JSON.stringify(n)}`); | ||
return s === "fields" ? y += ` RETURN ${l.join(", ")}` : s && (y += ` RETURN ${s.toUpperCase()}`), a && (y += ` TIMEOUT ${a}s`), f && (y += " PARALLEL"), y; | ||
} | ||
}; | ||
let me = I; | ||
S = new WeakMap(), ae = new WeakSet(), Ce = function() { | ||
S = new WeakMap(), ae = new WeakSet(), Te = function() { | ||
return Object.keys(r(this, S).setFields).length > 0; | ||
@@ -716,11 +716,11 @@ }, X = new WeakSet(), we = function() { | ||
}; | ||
function Et(...t) { | ||
if (t.length === 0) | ||
function Ot(...e) { | ||
if (e.length === 0) | ||
throw new b("At least one target must be specified"); | ||
if (de(...t)) | ||
if (de(...e)) | ||
throw new b("Multiple targets must be specified seperately"); | ||
return new me({ | ||
schema: null, | ||
quantity: t.length === 1 ? "one" : "many", | ||
targets: t.map((e) => V(e)).join(", "), | ||
quantity: e.length === 1 ? "one" : "many", | ||
targets: e.map((t) => V(t)).join(", "), | ||
setFields: {}, | ||
@@ -734,7 +734,7 @@ content: {}, | ||
} | ||
function bt(t, e) { | ||
function At(e, t) { | ||
return new me({ | ||
schema: null, | ||
quantity: "one", | ||
targets: le(t, e), | ||
targets: le(e, t), | ||
setFields: {}, | ||
@@ -748,86 +748,86 @@ content: {}, | ||
} | ||
function B(t) { | ||
return a(`= ${o(t)}`); | ||
function B(e) { | ||
return o(`= ${u(e)}`); | ||
} | ||
function Nt(t) { | ||
return a(`!= ${o(t)}`); | ||
function jt(e) { | ||
return o(`!= ${u(e)}`); | ||
} | ||
function qt(t) { | ||
return a(`== ${o(t)}`); | ||
function vt(e) { | ||
return o(`== ${u(e)}`); | ||
} | ||
function St(t) { | ||
return a(`?= ${o(t)}`); | ||
function Ft(e) { | ||
return o(`?= ${u(e)}`); | ||
} | ||
function Rt(t) { | ||
return a(`*= ${o(t)}`); | ||
function Mt(e) { | ||
return o(`*= ${u(e)}`); | ||
} | ||
function Ct(t) { | ||
return a(`~ ${o(t)}`); | ||
function It(e) { | ||
return o(`~ ${u(e)}`); | ||
} | ||
function Tt(t) { | ||
return a(`!~ ${o(t)}`); | ||
function Lt(e) { | ||
return o(`!~ ${u(e)}`); | ||
} | ||
function At(t) { | ||
return a(`?~ ${o(t)}`); | ||
function Ut(e) { | ||
return o(`?~ ${u(e)}`); | ||
} | ||
function Ot(t) { | ||
return a(`*~ ${o(t)}`); | ||
function kt(e) { | ||
return o(`*~ ${u(e)}`); | ||
} | ||
function jt(t) { | ||
return a(`< ${o(t)}`); | ||
function xt(e) { | ||
return o(`< ${u(e)}`); | ||
} | ||
function vt(t) { | ||
return a(`<= ${o(t)}`); | ||
function Pt(e) { | ||
return o(`<= ${u(e)}`); | ||
} | ||
function Ft(t) { | ||
return a(`> ${o(t)}`); | ||
function Qt(e) { | ||
return o(`> ${u(e)}`); | ||
} | ||
function Mt(t) { | ||
return a(`>= ${o(t)}`); | ||
function Dt(e) { | ||
return o(`>= ${u(e)}`); | ||
} | ||
function It(t) { | ||
return a(`CONTAINS ${o(t)}`); | ||
function Jt(e) { | ||
return o(`CONTAINS ${u(e)}`); | ||
} | ||
function Lt(t) { | ||
return a(`CONTAINSNOT ${o(t)}`); | ||
function zt(e) { | ||
return o(`CONTAINSNOT ${u(e)}`); | ||
} | ||
function Ut(t) { | ||
return a(`CONTAINSALL ${o(t)}`); | ||
function Bt(e) { | ||
return o(`CONTAINSALL ${u(e)}`); | ||
} | ||
function xt(t) { | ||
return a(`CONTAINSANY ${o(t)}`); | ||
function Gt(e) { | ||
return o(`CONTAINSANY ${u(e)}`); | ||
} | ||
function kt(t) { | ||
return a(`CONTAINSNONE ${o(t)}`); | ||
function Ht(e) { | ||
return o(`CONTAINSNONE ${u(e)}`); | ||
} | ||
function Pt(t) { | ||
return a(`INSIDE ${o(t)}`); | ||
function Yt(e) { | ||
return o(`INSIDE ${u(e)}`); | ||
} | ||
function Qt(t) { | ||
return a(`NOTINSIDE ${o(t)}`); | ||
function Vt(e) { | ||
return o(`NOTINSIDE ${u(e)}`); | ||
} | ||
function Dt(t) { | ||
return a(`ALLINSIDE ${o(t)}`); | ||
function Zt(e) { | ||
return o(`ALLINSIDE ${u(e)}`); | ||
} | ||
function Jt(t) { | ||
return a(`ANYINSIDE ${o(t)}`); | ||
function Kt(e) { | ||
return o(`ANYINSIDE ${u(e)}`); | ||
} | ||
function zt(t) { | ||
return a(`NONEINSIDE ${o(t)}`); | ||
function Wt(e) { | ||
return o(`NONEINSIDE ${u(e)}`); | ||
} | ||
function Bt(t) { | ||
return a(`OUTSIDE ${o(t)}`); | ||
function Xt(e) { | ||
return o(`OUTSIDE ${u(e)}`); | ||
} | ||
function Gt(t) { | ||
return a(`INTERSECTS ${o(t)}`); | ||
function _t(e) { | ||
return o(`INTERSECTS ${u(e)}`); | ||
} | ||
function Ht(t) { | ||
return a(`+= ${o(t)}`); | ||
function en(e) { | ||
return o(`+= ${u(e)}`); | ||
} | ||
function Yt(t) { | ||
return a(`-= ${o(t)}`); | ||
function tn(e) { | ||
return o(`-= ${u(e)}`); | ||
} | ||
var z; | ||
const Me = class { | ||
constructor(e) { | ||
constructor(t) { | ||
p(this, z, void 0); | ||
@@ -837,3 +837,3 @@ j(this, "_fallback", 0); | ||
j(this, "_quantity", "one"); | ||
N(this, z, e); | ||
N(this, z, t); | ||
} | ||
@@ -851,8 +851,8 @@ get _state() { | ||
*/ | ||
where(e) { | ||
where(t) { | ||
if (r(this, z).relation) | ||
throw new b("Cannot use where clause with countRelation"); | ||
return typeof e == "object" && (e = k(e)), new Me({ | ||
return typeof t == "object" && (t = x(t)), new Me({ | ||
...r(this, z), | ||
where: e | ||
where: t | ||
}); | ||
@@ -862,12 +862,12 @@ } | ||
const { | ||
target: e, | ||
target: t, | ||
where: n | ||
} = r(this, z); | ||
if (!e) | ||
if (!t) | ||
throw new Error("No target specified"); | ||
let i = `SELECT count() FROM ${e}`; | ||
let i = `SELECT count() FROM ${t}`; | ||
return n && (i += ` WHERE ${n}`), i += " GROUP ALL", i; | ||
} | ||
_transform(e) { | ||
return e.map((n) => n.count); | ||
_transform(t) { | ||
return t.map((n) => n.count); | ||
} | ||
@@ -877,5 +877,5 @@ }; | ||
z = new WeakMap(); | ||
function Vt(t) { | ||
function nn(e) { | ||
return new ie({ | ||
target: V(t), | ||
target: V(e), | ||
where: void 0, | ||
@@ -885,5 +885,5 @@ relation: !1 | ||
} | ||
function Zt(t, e) { | ||
function rn(e, t) { | ||
return new ie({ | ||
target: e === void 0 ? JSON.stringify(t) : le(t, e), | ||
target: t === void 0 ? JSON.stringify(e) : le(e, t), | ||
where: void 0, | ||
@@ -893,8 +893,8 @@ relation: !1 | ||
} | ||
function Kt(t) { | ||
function sn(e) { | ||
return new ie({ | ||
target: t.edge, | ||
where: k({ | ||
in: B(he(t)), | ||
out: B(fe(t)) | ||
target: e.edge, | ||
where: x({ | ||
in: B(he(e)), | ||
out: B(fe(e)) | ||
}), | ||
@@ -904,16 +904,16 @@ relation: !0 | ||
} | ||
var O; | ||
var A; | ||
const Q = class { | ||
constructor(e) { | ||
p(this, O, void 0); | ||
N(this, O, e); | ||
constructor(t) { | ||
p(this, A, void 0); | ||
N(this, A, t); | ||
} | ||
get _schema() { | ||
return r(this, O).schema; | ||
return r(this, A).schema; | ||
} | ||
get _quantity() { | ||
return r(this, O).quantity; | ||
return r(this, A).quantity; | ||
} | ||
get _state() { | ||
return Object.freeze({ ...r(this, O) }); | ||
return Object.freeze({ ...r(this, A) }); | ||
} | ||
@@ -927,6 +927,6 @@ /** | ||
*/ | ||
with(e) { | ||
with(t) { | ||
return new Q({ | ||
...r(this, O), | ||
schema: e | ||
...r(this, A), | ||
schema: t | ||
}); | ||
@@ -942,4 +942,4 @@ } | ||
*/ | ||
withSchema(e) { | ||
return this.with(q.object(e)); | ||
withSchema(t) { | ||
return this.with(q.object(t)); | ||
} | ||
@@ -964,8 +964,8 @@ /** | ||
*/ | ||
where(e) { | ||
if (r(this, O).unrelate) | ||
where(t) { | ||
if (r(this, A).unrelate) | ||
throw new b("Cannot use where clause with delRelation"); | ||
return typeof e == "object" && (e = k(e)), new Q({ | ||
...r(this, O), | ||
where: e | ||
return typeof t == "object" && (t = x(t)), new Q({ | ||
...r(this, A), | ||
where: t | ||
}); | ||
@@ -979,6 +979,6 @@ } | ||
*/ | ||
return(e) { | ||
return(t) { | ||
return new Q({ | ||
...r(this, O), | ||
returnMode: e | ||
...r(this, A), | ||
returnMode: t | ||
}); | ||
@@ -992,7 +992,7 @@ } | ||
*/ | ||
returnFields(...e) { | ||
returnFields(...t) { | ||
return new Q({ | ||
...r(this, O), | ||
...r(this, A), | ||
returnMode: "fields", | ||
returnFields: e | ||
returnFields: t | ||
}); | ||
@@ -1006,6 +1006,6 @@ } | ||
*/ | ||
timeout(e) { | ||
timeout(t) { | ||
return new Q({ | ||
...r(this, O), | ||
timeout: e | ||
...r(this, A), | ||
timeout: t | ||
}); | ||
@@ -1020,3 +1020,3 @@ } | ||
return new Q({ | ||
...r(this, O), | ||
...r(this, A), | ||
parallel: !0 | ||
@@ -1027,3 +1027,3 @@ }); | ||
const { | ||
targets: e, | ||
targets: t, | ||
where: n, | ||
@@ -1033,16 +1033,16 @@ returnMode: i, | ||
timeout: l, | ||
parallel: u | ||
} = r(this, O); | ||
if (!e) | ||
parallel: a | ||
} = r(this, A); | ||
if (!t) | ||
throw new Error("No targets specified"); | ||
let f = `DELETE ${e}`; | ||
return n && (f += ` WHERE ${n}`), i === "fields" ? f += ` RETURN ${s.join(", ")}` : i && (f += ` RETURN ${i.toUpperCase()}`), l && (f += ` TIMEOUT ${l}s`), u && (f += " PARALLEL"), f; | ||
let f = `DELETE ${t}`; | ||
return n && (f += ` WHERE ${n}`), i === "fields" ? f += ` RETURN ${s.join(", ")}` : i && (f += ` RETURN ${i.toUpperCase()}`), l && (f += ` TIMEOUT ${l}s`), a && (f += " PARALLEL"), f; | ||
} | ||
}; | ||
let se = Q; | ||
O = new WeakMap(); | ||
function Wt(...t) { | ||
if (t.length === 0) | ||
A = new WeakMap(); | ||
function on(...e) { | ||
if (e.length === 0) | ||
throw new b("At least one target must be specified"); | ||
if (de(...t)) | ||
if (de(...e)) | ||
throw new b("Multiple targets must be specified seperately"); | ||
@@ -1052,3 +1052,3 @@ return new se({ | ||
quantity: "many", | ||
targets: t.map((e) => V(e)).join(", "), | ||
targets: e.map((t) => V(t)).join(", "), | ||
where: void 0, | ||
@@ -1062,7 +1062,7 @@ returnMode: "before", | ||
} | ||
function Xt(t, e) { | ||
function un(e, t) { | ||
return new se({ | ||
schema: null, | ||
quantity: "maybe", | ||
targets: e === void 0 ? JSON.stringify(t) : le(t, e), | ||
targets: t === void 0 ? JSON.stringify(e) : le(e, t), | ||
where: void 0, | ||
@@ -1076,10 +1076,10 @@ returnMode: "before", | ||
} | ||
function _t(t) { | ||
function an(e) { | ||
return new se({ | ||
schema: null, | ||
quantity: "maybe", | ||
targets: t.edge, | ||
where: k({ | ||
in: B(he(t)), | ||
out: B(fe(t)) | ||
targets: e.edge, | ||
where: x({ | ||
in: B(he(e)), | ||
out: B(fe(e)) | ||
}), | ||
@@ -1095,3 +1095,3 @@ returnMode: "before", | ||
const L = class { | ||
constructor(e) { | ||
constructor(t) { | ||
p(this, ce); | ||
@@ -1101,3 +1101,3 @@ p(this, _); | ||
j(this, "_quantity", "one"); | ||
N(this, R, e); | ||
N(this, R, t); | ||
} | ||
@@ -1117,6 +1117,6 @@ get _schema() { | ||
*/ | ||
with(e) { | ||
with(t) { | ||
return new L({ | ||
...r(this, R), | ||
schema: e | ||
schema: t | ||
}); | ||
@@ -1132,4 +1132,4 @@ } | ||
*/ | ||
withSchema(e) { | ||
return this.with(q.object(e)); | ||
withSchema(t) { | ||
return this.with(q.object(t)); | ||
} | ||
@@ -1153,3 +1153,3 @@ /** | ||
*/ | ||
set(e, n) { | ||
set(t, n) { | ||
if (E(this, _, pe).call(this)) | ||
@@ -1161,3 +1161,3 @@ throw new b("Cannot set field when content is set"); | ||
...r(this, R).setFields, | ||
[e]: n | ||
[t]: n | ||
} | ||
@@ -1174,3 +1174,3 @@ }); | ||
*/ | ||
setAll(e) { | ||
setAll(t) { | ||
if (E(this, _, pe).call(this)) | ||
@@ -1182,3 +1182,3 @@ throw new b("Cannot set fields when content is set"); | ||
...r(this, R).setFields, | ||
...e | ||
...t | ||
} | ||
@@ -1196,3 +1196,3 @@ }); | ||
*/ | ||
content(e) { | ||
content(t) { | ||
if (E(this, ce, Ae).call(this)) | ||
@@ -1202,3 +1202,3 @@ throw new b("Cannot set content when fields are set"); | ||
...r(this, R), | ||
content: e | ||
content: t | ||
}); | ||
@@ -1212,6 +1212,6 @@ } | ||
*/ | ||
return(e) { | ||
return(t) { | ||
return new L({ | ||
...r(this, R), | ||
returnMode: e | ||
returnMode: t | ||
}); | ||
@@ -1225,7 +1225,7 @@ } | ||
*/ | ||
returnFields(...e) { | ||
returnFields(...t) { | ||
return new L({ | ||
...r(this, R), | ||
returnMode: "fields", | ||
returnFields: e | ||
returnFields: t | ||
}); | ||
@@ -1239,6 +1239,6 @@ } | ||
*/ | ||
timeout(e) { | ||
timeout(t) { | ||
return new L({ | ||
...r(this, R), | ||
timeout: e | ||
timeout: t | ||
}); | ||
@@ -1259,3 +1259,3 @@ } | ||
const { | ||
from: e, | ||
from: t, | ||
edge: n, | ||
@@ -1265,10 +1265,10 @@ to: i, | ||
setFields: l, | ||
returnMode: u, | ||
returnMode: a, | ||
returnFields: f, | ||
timeout: g, | ||
timeout: y, | ||
parallel: w | ||
} = r(this, R); | ||
if (!e || !n || !i) | ||
if (!t || !n || !i) | ||
throw new Error("From, edge, and to must be defined"); | ||
let d = `RELATE ${e}->${n}->${i}`; | ||
let d = `RELATE ${t}->${n}->${i}`; | ||
if (E(this, ce, Ae).call(this)) { | ||
@@ -1279,6 +1279,6 @@ const m = Fe(l); | ||
E(this, _, pe).call(this) && (d += ` CONTENT ${JSON.stringify(s)}`); | ||
return u === "fields" ? d += ` RETURN ${f.join(", ")}` : u && (d += ` RETURN ${u.toUpperCase()}`), g && (d += ` TIMEOUT ${g}s`), w && (d += " PARALLEL"), d; | ||
return a === "fields" ? d += ` RETURN ${f.join(", ")}` : a && (d += ` RETURN ${a.toUpperCase()}`), y && (d += ` TIMEOUT ${y}s`), w && (d += " PARALLEL"), d; | ||
} | ||
}; | ||
let Te = L; | ||
let Oe = L; | ||
R = new WeakMap(), ce = new WeakSet(), Ae = function() { | ||
@@ -1289,7 +1289,7 @@ return Object.keys(r(this, R).setFields).length > 0; | ||
}; | ||
function lt(t, e, n) { | ||
return new Te({ | ||
function lt(e, t, n) { | ||
return new Oe({ | ||
schema: null, | ||
from: V(t, !0), | ||
edge: e, | ||
from: V(e, !0), | ||
edge: t, | ||
to: V(n, !0), | ||
@@ -1304,20 +1304,20 @@ setFields: {}, | ||
} | ||
function en(t) { | ||
const e = he(t), n = fe(t); | ||
return lt(`(${e[U]})`, t.edge, `(${n[U]})`); | ||
function cn(e) { | ||
const t = he(e), n = fe(e); | ||
return lt(`(${t[U]})`, e.edge, `(${n[U]})`); | ||
} | ||
var y; | ||
var g; | ||
const T = class { | ||
constructor(e) { | ||
p(this, y, void 0); | ||
N(this, y, e); | ||
constructor(t) { | ||
p(this, g, void 0); | ||
N(this, g, t); | ||
} | ||
get _schema() { | ||
return r(this, y).schema; | ||
return r(this, g).schema; | ||
} | ||
get _quantity() { | ||
return r(this, y).quantity; | ||
return r(this, g).quantity; | ||
} | ||
get _state() { | ||
return Object.freeze({ ...r(this, y) }); | ||
return Object.freeze({ ...r(this, g) }); | ||
} | ||
@@ -1331,6 +1331,6 @@ /** | ||
*/ | ||
with(e) { | ||
with(t) { | ||
return new T({ | ||
...r(this, y), | ||
schema: e | ||
...r(this, g), | ||
schema: t | ||
}); | ||
@@ -1346,4 +1346,4 @@ } | ||
*/ | ||
withSchema(e) { | ||
return this.with(q.object(e)); | ||
withSchema(t) { | ||
return this.with(q.object(t)); | ||
} | ||
@@ -1368,6 +1368,6 @@ /** | ||
*/ | ||
and(e) { | ||
and(t) { | ||
return new T({ | ||
...r(this, y), | ||
projections: [...r(this, y).projections, e] | ||
...r(this, g), | ||
projections: [...r(this, g).projections, t] | ||
}); | ||
@@ -1383,4 +1383,4 @@ } | ||
*/ | ||
andQuery(e, n) { | ||
return this.and(`(${n.toQuery()}) AS ${e}`); | ||
andQuery(t, n) { | ||
return this.and(`(${n.toQuery()}) AS ${t}`); | ||
} | ||
@@ -1394,4 +1394,4 @@ /** | ||
*/ | ||
from(...e) { | ||
const n = e.map((i) => { | ||
from(...t) { | ||
const n = t.map((i) => { | ||
if (typeof i == "string" && de(i)) | ||
@@ -1402,11 +1402,11 @@ throw new b("Multiple targets must be specified seperately"); | ||
return new T({ | ||
...r(this, y), | ||
...r(this, g), | ||
targets: n.join(", ") | ||
}); | ||
} | ||
fromRecord(e, n) { | ||
fromRecord(t, n) { | ||
return new T({ | ||
...r(this, y), | ||
...r(this, g), | ||
quantity: "maybe", | ||
targets: n === void 0 ? JSON.stringify(e) : le(e, n), | ||
targets: n === void 0 ? JSON.stringify(t) : le(t, n), | ||
limit: 1 | ||
@@ -1427,11 +1427,11 @@ }); | ||
*/ | ||
fromRelation(e) { | ||
fromRelation(t) { | ||
return new T({ | ||
...r(this, y), | ||
...r(this, g), | ||
quantity: "maybe", | ||
relation: !0, | ||
targets: e.edge, | ||
where: k({ | ||
in: B(he(e)), | ||
out: B(fe(e)) | ||
targets: t.edge, | ||
where: x({ | ||
in: B(he(t)), | ||
out: B(fe(t)) | ||
}) | ||
@@ -1448,8 +1448,8 @@ }); | ||
*/ | ||
where(e) { | ||
if (r(this, y).relation) | ||
where(t) { | ||
if (r(this, g).relation) | ||
throw new b("Cannot use where clause with fromRelation"); | ||
return typeof e == "object" && (e = k(e)), new T({ | ||
...r(this, y), | ||
where: e | ||
return typeof t == "object" && (t = x(t)), new T({ | ||
...r(this, g), | ||
where: t | ||
}); | ||
@@ -1463,6 +1463,6 @@ } | ||
*/ | ||
split(...e) { | ||
split(...t) { | ||
return new T({ | ||
...r(this, y), | ||
split: e | ||
...r(this, g), | ||
split: t | ||
}); | ||
@@ -1477,6 +1477,6 @@ } | ||
*/ | ||
groupBy(...e) { | ||
groupBy(...t) { | ||
return new T({ | ||
...r(this, y), | ||
group: e | ||
...r(this, g), | ||
group: t | ||
}); | ||
@@ -1491,10 +1491,10 @@ } | ||
return new T({ | ||
...r(this, y), | ||
...r(this, g), | ||
group: "all" | ||
}); | ||
} | ||
orderBy(e, n) { | ||
const i = typeof e == "string" ? { [e]: n || "asc" } : e; | ||
orderBy(t, n) { | ||
const i = typeof t == "string" ? { [t]: n || "asc" } : t; | ||
return new T({ | ||
...r(this, y), | ||
...r(this, g), | ||
order: i | ||
@@ -1509,7 +1509,7 @@ }); | ||
*/ | ||
limit(e) { | ||
limit(t) { | ||
return new T({ | ||
...r(this, y), | ||
...r(this, g), | ||
quantity: "many", | ||
limit: e | ||
limit: t | ||
}); | ||
@@ -1528,3 +1528,3 @@ } | ||
return new T({ | ||
...r(this, y), | ||
...r(this, g), | ||
quantity: "maybe", | ||
@@ -1540,6 +1540,6 @@ limit: 1 | ||
*/ | ||
start(e) { | ||
start(t) { | ||
return new T({ | ||
...r(this, y), | ||
start: e | ||
...r(this, g), | ||
start: t | ||
}); | ||
@@ -1553,6 +1553,6 @@ } | ||
*/ | ||
fetch(...e) { | ||
fetch(...t) { | ||
return new T({ | ||
...r(this, y), | ||
fetch: e | ||
...r(this, g), | ||
fetch: t | ||
}); | ||
@@ -1566,6 +1566,6 @@ } | ||
*/ | ||
timeout(e) { | ||
timeout(t) { | ||
return new T({ | ||
...r(this, y), | ||
timeout: e | ||
...r(this, g), | ||
timeout: t | ||
}); | ||
@@ -1580,3 +1580,3 @@ } | ||
return new T({ | ||
...r(this, y), | ||
...r(this, g), | ||
parallel: !0 | ||
@@ -1587,3 +1587,3 @@ }); | ||
const { | ||
projections: e, | ||
projections: t, | ||
targets: n, | ||
@@ -1593,10 +1593,10 @@ where: i, | ||
group: l, | ||
order: u, | ||
order: a, | ||
limit: f, | ||
start: g, | ||
start: y, | ||
fetch: w, | ||
timeout: d, | ||
parallel: m | ||
} = r(this, y); | ||
if (e) { | ||
} = r(this, g); | ||
if (t) { | ||
if (!n) | ||
@@ -1606,20 +1606,20 @@ throw new Error("No targets specified"); | ||
throw new Error("No projections specified"); | ||
const x = e.length > 0 ? e.join(", ") : "*", h = Object.entries(u); | ||
let c = `SELECT ${x} FROM ${n}`; | ||
const k = t.length > 0 ? t.join(", ") : "*", h = Object.entries(a); | ||
let c = `SELECT ${k} FROM ${n}`; | ||
if (i && (c += ` WHERE ${i}`), s.length > 0 && (c += ` SPLIT ${s.join(", ")}`), l === "all" ? c += " GROUP ALL" : l.length > 0 && (c += ` GROUP BY ${l.join(", ")}`), h.length > 0) { | ||
const C = h.map(([v, A]) => `${v} ${A.toUpperCase()}`); | ||
const C = h.map(([v, O]) => `${v} ${O.toUpperCase()}`); | ||
c += ` ORDER BY ${C.join(", ")}`; | ||
} | ||
return f && (c += ` LIMIT BY ${f}`), g && (c += ` START AT ${g}`), w.length > 0 && (c += ` FETCH ${w.join(", ")}`), d && (c += ` TIMEOUT ${d}s`), m && (c += " PARALLEL"), c; | ||
return f && (c += ` LIMIT BY ${f}`), y && (c += ` START AT ${y}`), w.length > 0 && (c += ` FETCH ${w.join(", ")}`), d && (c += ` TIMEOUT ${d}s`), m && (c += " PARALLEL"), c; | ||
} | ||
}; | ||
let Oe = T; | ||
y = new WeakMap(); | ||
function tn(...t) { | ||
if (de(...t)) | ||
let je = T; | ||
g = new WeakMap(); | ||
function ln(...e) { | ||
if (de(...e)) | ||
throw new b("Multiple projections must be specified seperately"); | ||
return new Oe({ | ||
return new je({ | ||
schema: null, | ||
quantity: "many", | ||
projections: t, | ||
projections: e, | ||
targets: void 0, | ||
@@ -1638,9 +1638,9 @@ where: void 0, | ||
} | ||
var $, ee, ye, te, ge; | ||
var $, ee, ge, te, ye; | ||
const F = class { | ||
constructor(e) { | ||
constructor(t) { | ||
p(this, ee); | ||
p(this, te); | ||
p(this, $, void 0); | ||
N(this, $, e); | ||
N(this, $, t); | ||
} | ||
@@ -1663,6 +1663,6 @@ get _schema() { | ||
*/ | ||
with(e) { | ||
with(t) { | ||
return new F({ | ||
...r(this, $), | ||
schema: e | ||
schema: t | ||
}); | ||
@@ -1678,4 +1678,4 @@ } | ||
*/ | ||
withSchema(e) { | ||
return this.with(q.object(e)); | ||
withSchema(t) { | ||
return this.with(q.object(t)); | ||
} | ||
@@ -1699,4 +1699,4 @@ /** | ||
*/ | ||
set(e, n) { | ||
if (E(this, te, ge).call(this)) | ||
set(t, n) { | ||
if (E(this, te, ye).call(this)) | ||
throw new b("Cannot set field when content is set"); | ||
@@ -1707,3 +1707,3 @@ return new F({ | ||
...r(this, $).setFields, | ||
[e]: n | ||
[t]: n | ||
} | ||
@@ -1720,4 +1720,4 @@ }); | ||
*/ | ||
setAll(e) { | ||
if (E(this, te, ge).call(this)) | ||
setAll(t) { | ||
if (E(this, te, ye).call(this)) | ||
throw new b("Cannot set fields when content is set"); | ||
@@ -1728,3 +1728,3 @@ return new F({ | ||
...r(this, $).setFields, | ||
...e | ||
...t | ||
} | ||
@@ -1742,8 +1742,8 @@ }); | ||
*/ | ||
content(e) { | ||
if (E(this, ee, ye).call(this)) | ||
content(t) { | ||
if (E(this, ee, ge).call(this)) | ||
throw new b("Cannot set content when fields are set"); | ||
return new F({ | ||
...r(this, $), | ||
content: e, | ||
content: t, | ||
contentMode: "replace" | ||
@@ -1761,8 +1761,8 @@ }); | ||
*/ | ||
merge(e) { | ||
if (E(this, ee, ye).call(this)) | ||
merge(t) { | ||
if (E(this, ee, ge).call(this)) | ||
throw new b("Cannot set content when fields are set"); | ||
return new F({ | ||
...r(this, $), | ||
content: e, | ||
content: t, | ||
contentMode: "merge" | ||
@@ -1779,8 +1779,8 @@ }); | ||
*/ | ||
where(e) { | ||
where(t) { | ||
if (r(this, $).relation) | ||
throw new b("Cannot use where clause with updateRelation"); | ||
return typeof e == "object" && (e = k(e)), new F({ | ||
return typeof t == "object" && (t = x(t)), new F({ | ||
...r(this, $), | ||
where: e | ||
where: t | ||
}); | ||
@@ -1794,6 +1794,6 @@ } | ||
*/ | ||
return(e) { | ||
return(t) { | ||
return new F({ | ||
...r(this, $), | ||
returnMode: e | ||
returnMode: t | ||
}); | ||
@@ -1807,7 +1807,7 @@ } | ||
*/ | ||
returnFields(...e) { | ||
returnFields(...t) { | ||
return new F({ | ||
...r(this, $), | ||
returnMode: "fields", | ||
returnFields: e | ||
returnFields: t | ||
}); | ||
@@ -1821,6 +1821,6 @@ } | ||
*/ | ||
timeout(e) { | ||
timeout(t) { | ||
return new F({ | ||
...r(this, $), | ||
timeout: e | ||
timeout: t | ||
}); | ||
@@ -1841,3 +1841,3 @@ } | ||
const { | ||
targets: e, | ||
targets: t, | ||
content: n, | ||
@@ -1847,28 +1847,28 @@ contentMode: i, | ||
where: l, | ||
returnMode: u, | ||
returnMode: a, | ||
returnFields: f, | ||
timeout: g, | ||
timeout: y, | ||
parallel: w | ||
} = r(this, $); | ||
if (!e) | ||
if (!t) | ||
throw new Error("No targets specified"); | ||
let d = `UPDATE ${e}`; | ||
if (E(this, ee, ye).call(this)) { | ||
let d = `UPDATE ${t}`; | ||
if (E(this, ee, ge).call(this)) { | ||
const m = Fe(s); | ||
m && (d += ` SET ${m}`); | ||
} else | ||
E(this, te, ge).call(this) && (d += ` ${i === "merge" ? "MERGE" : "CONTENT"} ${JSON.stringify(n)}`); | ||
return l && (d += ` WHERE ${l}`), u === "fields" ? d += ` RETURN ${f.join(", ")}` : u && (d += ` RETURN ${u.toUpperCase()}`), g && (d += ` TIMEOUT ${g}s`), w && (d += " PARALLEL"), d; | ||
E(this, te, ye).call(this) && (d += ` ${i === "merge" ? "MERGE" : "CONTENT"} ${JSON.stringify(n)}`); | ||
return l && (d += ` WHERE ${l}`), a === "fields" ? d += ` RETURN ${f.join(", ")}` : a && (d += ` RETURN ${a.toUpperCase()}`), y && (d += ` TIMEOUT ${y}s`), w && (d += " PARALLEL"), d; | ||
} | ||
}; | ||
let oe = F; | ||
$ = new WeakMap(), ee = new WeakSet(), ye = function() { | ||
$ = new WeakMap(), ee = new WeakSet(), ge = function() { | ||
return Object.keys(r(this, $).setFields).length > 0; | ||
}, te = new WeakSet(), ge = function() { | ||
}, te = new WeakSet(), ye = function() { | ||
return Object.keys(r(this, $).content).length > 0; | ||
}; | ||
function nn(...t) { | ||
if (t.length === 0) | ||
function hn(...e) { | ||
if (e.length === 0) | ||
throw new b("At least one target must be specified"); | ||
if (de(...t)) | ||
if (de(...e)) | ||
throw new b("Multiple targets must be specified seperately"); | ||
@@ -1878,3 +1878,3 @@ return new oe({ | ||
quantity: "many", | ||
targets: t.map((e) => V(e)).join(", "), | ||
targets: e.map((t) => V(t)).join(", "), | ||
setFields: {}, | ||
@@ -1891,7 +1891,7 @@ content: {}, | ||
} | ||
function rn(t, e) { | ||
function fn(e, t) { | ||
return new oe({ | ||
schema: null, | ||
quantity: "maybe", | ||
targets: e === void 0 ? JSON.stringify(t) : le(t, e), | ||
targets: t === void 0 ? JSON.stringify(e) : le(e, t), | ||
setFields: {}, | ||
@@ -1908,10 +1908,10 @@ content: {}, | ||
} | ||
function sn(t) { | ||
function dn(e) { | ||
return new oe({ | ||
schema: null, | ||
quantity: "maybe", | ||
targets: t.edge, | ||
where: k({ | ||
in: B(he(t)), | ||
out: B(fe(t)) | ||
targets: e.edge, | ||
where: x({ | ||
in: B(he(e)), | ||
out: B(fe(e)) | ||
}), | ||
@@ -1930,7 +1930,7 @@ setFields: {}, | ||
const Ne = class { | ||
constructor(e, n, i) { | ||
constructor(t, n, i) { | ||
p(this, ne, void 0); | ||
p(this, Y, void 0); | ||
p(this, re, void 0); | ||
N(this, ne, e), N(this, Y, n), N(this, re, i); | ||
N(this, ne, t), N(this, Y, n), N(this, re, i); | ||
} | ||
@@ -1950,4 +1950,4 @@ get _quantity() { | ||
*/ | ||
with(e) { | ||
return new Ne(e, r(this, Y), r(this, re)); | ||
with(t) { | ||
return new Ne(t, r(this, Y), r(this, re)); | ||
} | ||
@@ -1962,4 +1962,4 @@ /** | ||
*/ | ||
withSchema(e) { | ||
return this.with(q.object(e)); | ||
withSchema(t) { | ||
return this.with(q.object(t)); | ||
} | ||
@@ -1988,11 +1988,11 @@ /** | ||
}; | ||
let je = Ne; | ||
let ve = Ne; | ||
ne = new WeakMap(), Y = new WeakMap(), re = new WeakMap(); | ||
function ht(t) { | ||
return new je(null, t, "many"); | ||
function ht(e) { | ||
return new ve(null, e, "many"); | ||
} | ||
const ft = /^[a-zA-Z0-9_]*$/; | ||
function on(t, e) { | ||
if (!ft.test(t)) | ||
throw new Error(`Invalid LET name: ${t}`); | ||
function wn(e, t) { | ||
if (!ft.test(e)) | ||
throw new Error(`Invalid LET name: ${e}`); | ||
return { | ||
@@ -2002,9 +2002,9 @@ _quantity: "zero", | ||
toQuery() { | ||
return `LET $${t} = ${o(e)}`; | ||
return `LET $${e} = ${u(t)}`; | ||
} | ||
}; | ||
} | ||
const un = q.object({ | ||
const pn = q.object({ | ||
id: q.string() | ||
}), an = q.object({ | ||
}), gn = q.object({ | ||
id: q.string(), | ||
@@ -2014,5 +2014,5 @@ in: q.string(), | ||
}); | ||
function cn(t) { | ||
return t.trim().split(";").filter((e) => !!e).map((e) => ({ | ||
query: ht(e), | ||
function yn(e) { | ||
return e.trim().split(";").filter((t) => !!t).map((t) => ({ | ||
query: ht(t), | ||
schema: q.any() | ||
@@ -2022,14 +2022,48 @@ })); | ||
function dt() { | ||
return a("time::now()"); | ||
return o("time::now()"); | ||
} | ||
const ln = { | ||
const mn = { | ||
now: dt | ||
}; | ||
function wt() { | ||
return o("rand::bool()"); | ||
} | ||
function pt(e) { | ||
return o(`rand::enum(${e.map(u).join(", ")})`); | ||
} | ||
function gt(e = 0, t = 1) { | ||
return o(`rand::float(${e}, ${t})`); | ||
} | ||
function yt(e) { | ||
return o(`rand::guid(${e ?? ""})`); | ||
} | ||
function mt(e, t) { | ||
return o(e && t ? `rand::int(${e}, ${t})` : "rand::int()"); | ||
} | ||
function $t(e) { | ||
return o(`rand::string(${e ?? ""})`); | ||
} | ||
function Et(e, t) { | ||
return o(e && t ? `rand::time(${e}, ${t})` : "rand::time()"); | ||
} | ||
function bt() { | ||
return o("rand::uuid()"); | ||
} | ||
const $n = { | ||
bool: wt, | ||
enumOf: pt, | ||
float: gt, | ||
guid: yt, | ||
int: mt, | ||
string: $t, | ||
time: Et, | ||
uuid: bt | ||
}; | ||
export { | ||
mt as Cirql, | ||
Se as CirqlAuthenticationError, | ||
Ct as Cirql, | ||
Re as CirqlAuthenticationError, | ||
M as CirqlError, | ||
Ve as CirqlParseError, | ||
Ze as CirqlQueryError, | ||
$t as CirqlStateless, | ||
Tt as CirqlStateless, | ||
b as CirqlWriterError, | ||
@@ -2039,55 +2073,56 @@ ie as CountQueryWriter, | ||
se as DeleteQueryWriter, | ||
an as EdgeSchema, | ||
un as RecordSchema, | ||
Te as RelateQueryWriter, | ||
Oe as SelectQueryWriter, | ||
gn as EdgeSchema, | ||
pn as RecordSchema, | ||
Oe as RelateQueryWriter, | ||
je as SelectQueryWriter, | ||
oe as UpdateQueryWriter, | ||
Ht as add, | ||
Rt as all, | ||
Dt as allInside, | ||
St as any, | ||
Jt as anyInside, | ||
It as contains, | ||
Ut as containsAll, | ||
xt as containsAny, | ||
kt as containsNone, | ||
Lt as containsNot, | ||
Vt as count, | ||
Zt as countRecord, | ||
Kt as countRelation, | ||
Et as create, | ||
bt as createRecord, | ||
Wt as del, | ||
Xt as delRecord, | ||
_t as delRelation, | ||
qt as eeq, | ||
en as add, | ||
Mt as all, | ||
Zt as allInside, | ||
Ft as any, | ||
Kt as anyInside, | ||
Jt as contains, | ||
Bt as containsAll, | ||
Gt as containsAny, | ||
Ht as containsNone, | ||
zt as containsNot, | ||
nn as count, | ||
rn as countRecord, | ||
sn as countRelation, | ||
Ot as create, | ||
At as createRecord, | ||
on as del, | ||
un as delRecord, | ||
an as delRelation, | ||
vt as eeq, | ||
B as eq, | ||
Ot as fall, | ||
At as fany, | ||
Ct as feq, | ||
Ft as gt, | ||
Mt as gte, | ||
Pt as inside, | ||
Gt as intersects, | ||
on as letValue, | ||
jt as lt, | ||
vt as lte, | ||
Nt as neq, | ||
Tt as nfeq, | ||
zt as noneInside, | ||
Qt as notInside, | ||
Bt as outside, | ||
gt as param, | ||
cn as parseQueries, | ||
kt as fall, | ||
Ut as fany, | ||
It as feq, | ||
Qt as gt, | ||
Dt as gte, | ||
Yt as inside, | ||
_t as intersects, | ||
wn as letValue, | ||
xt as lt, | ||
Pt as lte, | ||
jt as neq, | ||
Lt as nfeq, | ||
Wt as noneInside, | ||
Vt as notInside, | ||
Xt as outside, | ||
Rt as param, | ||
yn as parseQueries, | ||
ht as query, | ||
a as raw, | ||
$n as rand, | ||
o as raw, | ||
lt as relate, | ||
en as relateRelation, | ||
Yt as remove, | ||
tn as select, | ||
ln as time, | ||
cn as relateRelation, | ||
tn as remove, | ||
ln as select, | ||
mn as time, | ||
Ue as type, | ||
nn as update, | ||
rn as updateRecord, | ||
sn as updateRelation | ||
hn as update, | ||
fn as updateRecord, | ||
dn as updateRelation | ||
}; |
@@ -1541,3 +1541,3 @@ import { ZodTypeAny, input, TypeOf, ZodRawShape, z, ZodNumber, ZodUndefined, ZodError } from 'zod'; | ||
*/ | ||
declare function bool(value: SurrealValue): RawQuery; | ||
declare function bool$1(value: SurrealValue): RawQuery; | ||
/** | ||
@@ -1570,3 +1570,3 @@ * Inserts a raw function call for `type::datetime()` | ||
*/ | ||
declare function float(value: SurrealValue): RawQuery; | ||
declare function float$1(value: SurrealValue): RawQuery; | ||
/** | ||
@@ -1578,3 +1578,3 @@ * Inserts a raw function call for `type::int()` | ||
*/ | ||
declare function int(value: SurrealValue): RawQuery; | ||
declare function int$1(value: SurrealValue): RawQuery; | ||
/** | ||
@@ -1615,3 +1615,3 @@ * Inserts a raw function call for `type::number()` | ||
*/ | ||
declare function string(value: SurrealValue): RawQuery; | ||
declare function string$1(value: SurrealValue): RawQuery; | ||
/** | ||
@@ -1636,12 +1636,12 @@ * Inserts a raw function call for `type::table()` | ||
declare const type: { | ||
bool: typeof bool; | ||
bool: typeof bool$1; | ||
datetime: typeof datetime; | ||
decimal: typeof decimal; | ||
duration: typeof duration; | ||
float: typeof float; | ||
int: typeof int; | ||
float: typeof float$1; | ||
int: typeof int$1; | ||
number: typeof number; | ||
point: typeof point; | ||
regex: typeof regex; | ||
string: typeof string; | ||
string: typeof string$1; | ||
table: typeof table; | ||
@@ -1660,6 +1660,68 @@ thing: typeof thing; | ||
*/ | ||
declare const time: { | ||
declare const time$1: { | ||
now: typeof now; | ||
}; | ||
export { AuthenticationDetails, Cirql, CirqlAuthenticationError, CirqlBaseOptions, CirqlError, CirqlOptions, CirqlParseError, CirqlQueryError, CirqlStateless, CirqlStatelessOptions, CirqlWriterError, ConnectionDetails, CountQueryWriter, CreateQueryWriter, DatabaseAuth, DeleteQueryWriter, EdgeSchema, ErrorCodes, FieldOrRaw, InferredQueryRequest, MultiTypeOf, NamespaceAuth, OpenUnion, Order, Ordering, Params, QuantitativeTypeOf, Quantity, QueryRequest, QueryRequestBase, QueryWriter, RawQuery, RecordRelation, RecordSchema, RegistrationDetails, RelateQueryWriter, ReturnMode, RootAuth, Schema, SchemaFields, SchemaInput, SchemaQueryRequest, ScopeAuth, SelectQueryWriter, SoloTypeOf, SurrealValue, TokenAuth, UpdateQueryWriter, Where, add, all, allInside, any, anyInside, contains, containsAll, containsAny, containsNone, containsNot, count, countRecord, countRelation, create, createRecord, del, delRecord, delRelation, eeq, eq, fall, fany, feq, gt, gte, inside, intersects, letValue, lt, lte, neq, nfeq, noneInside, notInside, outside, param, parseQueries, query, raw, relate, relateRelation, remove, select, time, type, update, updateRecord, updateRelation }; | ||
/** | ||
* Inserts a raw function call for `rand::bool()` | ||
* | ||
* @returns The raw query | ||
*/ | ||
declare function bool(): RawQuery; | ||
/** | ||
* Inserts a raw function call for `rand::enum()` | ||
* | ||
* @returns The raw query | ||
*/ | ||
declare function enumOf(value: SurrealValue[]): RawQuery; | ||
/** | ||
* Inserts a raw function call for `rand::float()` | ||
* | ||
* @returns The raw query | ||
*/ | ||
declare function float(min?: number, max?: number): RawQuery; | ||
/** | ||
* Inserts a raw function call for `rand::guid()` | ||
* | ||
* @returns The raw query | ||
*/ | ||
declare function guid(length?: number): RawQuery; | ||
/** | ||
* Inserts a raw function call for `rand::int()` | ||
* | ||
* @returns The raw query | ||
*/ | ||
declare function int(min?: number, max?: number): RawQuery; | ||
/** | ||
* Inserts a raw function call for `rand::string()` | ||
* | ||
* @returns The raw query | ||
*/ | ||
declare function string(length?: number): RawQuery; | ||
/** | ||
* Inserts a raw function call for `rand::time()` | ||
* | ||
* @returns The raw query | ||
*/ | ||
declare function time(minUnix?: number, maxUnix?: number): RawQuery; | ||
/** | ||
* Inserts a raw function call for `rand::uuid()` | ||
* | ||
* @returns The raw query | ||
*/ | ||
declare function uuid(): RawQuery; | ||
/** | ||
* Raw query functions for the category `rand` | ||
*/ | ||
declare const rand: { | ||
bool: typeof bool; | ||
enumOf: typeof enumOf; | ||
float: typeof float; | ||
guid: typeof guid; | ||
int: typeof int; | ||
string: typeof string; | ||
time: typeof time; | ||
uuid: typeof uuid; | ||
}; | ||
export { AuthenticationDetails, Cirql, CirqlAuthenticationError, CirqlBaseOptions, CirqlError, CirqlOptions, CirqlParseError, CirqlQueryError, CirqlStateless, CirqlStatelessOptions, CirqlWriterError, ConnectionDetails, CountQueryWriter, CreateQueryWriter, DatabaseAuth, DeleteQueryWriter, EdgeSchema, ErrorCodes, FieldOrRaw, InferredQueryRequest, MultiTypeOf, NamespaceAuth, OpenUnion, Order, Ordering, Params, QuantitativeTypeOf, Quantity, QueryRequest, QueryRequestBase, QueryWriter, RawQuery, RecordRelation, RecordSchema, RegistrationDetails, RelateQueryWriter, ReturnMode, RootAuth, Schema, SchemaFields, SchemaInput, SchemaQueryRequest, ScopeAuth, SelectQueryWriter, SoloTypeOf, SurrealValue, TokenAuth, UpdateQueryWriter, Where, add, all, allInside, any, anyInside, contains, containsAll, containsAny, containsNone, containsNot, count, countRecord, countRelation, create, createRecord, del, delRecord, delRelation, eeq, eq, fall, fany, feq, gt, gte, inside, intersects, letValue, lt, lte, neq, nfeq, noneInside, notInside, outside, param, parseQueries, query, rand, raw, relate, relateRelation, remove, select, time$1 as time, type, update, updateRecord, updateRelation }; |
{ | ||
"name": "cirql", | ||
"version": "0.6.6", | ||
"version": "0.6.7", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
138799
3821