UNPKG

starknetkit

Version:

<!-- logo --> <p align="center"> <img width='300' src="https://starknetkit-website-git-blo-1541-argentlabs.vercel.app/starknetKit-logo.svg"> </p>

2,041 lines (2,040 loc) 168 kB
var On = Object.defineProperty; var Sn = (t, e, r) => e in t ? On(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r; var Te = (t, e, r) => (Sn(t, typeof e != "symbol" ? e + "" : e, r), r); import { constants as xr, WalletAccount as Pn } from "starknet"; import { g as kr, c as He, P as Ct, C as An, a as se, b as ht, U as er, r as Nn } from "./lastConnected-e9351912.js"; import { g as tr } from "./getStarknetChainId-7c4b3163.js"; const Tr = "https://web.argent.xyz", rr = `<svg width="32" height="28" viewBox="0 0 18 14" fill="none" xmlns="http://www.w3.org/2000/svg" > <path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 0.4375C0.982233 0.4375 0.5625 0.857233 0.5625 1.375V12C0.5625 12.4144 0.72712 12.8118 1.02015 13.1049C1.31317 13.3979 1.7106 13.5625 2.125 13.5625H15.875C16.2894 13.5625 16.6868 13.3979 16.9799 13.1049C17.2729 12.8118 17.4375 12.4144 17.4375 12V1.375C17.4375 0.857233 17.0178 0.4375 16.5 0.4375H1.5ZM2.4375 3.50616V11.6875H15.5625V3.50616L9.63349 8.94108C9.27507 9.26964 8.72493 9.26964 8.36651 8.94108L2.4375 3.50616ZM14.0899 2.3125H3.91013L9 6.97822L14.0899 2.3125Z" fill="currentColor" /> </svg>`, In = "https://static.hydrogen.argent47.net/webwallet/iframe_whitelist_testnet.json", jn = "https://static.argent.net/webwallet/iframe_whitelist_mainnet.json"; class Ln extends Error { constructor(r, n) { super(r); Te(this, "code"); this.name = "ConnectAndSignSessionError", this.code = n; } } class $n extends Error { constructor(r, n) { super(r); Te(this, "code"); this.name = "WebwalletError", this.code = n; } } const Q = xr.NetworkName, Mn = Q.SN_SEPOLIA; function Dn(t) { try { const { origin: e } = new URL(t); if (e.includes("localhost") || e.includes("127.0.0.1")) return Mn; if (e.includes("hydrogen") || e.includes("sepolia-web.staging")) return Q.SN_SEPOLIA; if (e.includes("staging")) return Q.SN_MAIN; if (e.includes("dev") || e.includes("sepolia-web.argent.xyz")) return Q.SN_SEPOLIA; if (e.includes("argent.xyz")) return Q.SN_MAIN; } catch { console.warn( "Could not determine network from target URL, defaulting to mainnet-alpha" ); } return Q.SN_MAIN; } const Zn = 385, Un = 775, Wn = 385, qn = 440, zn = 420, Bn = 438; function Vn(t) { return t; } function Fn(t) { return t.length === 0 ? Vn : t.length === 1 ? t[0] : function(r) { return t.reduce((n, s) => s(n), r); }; } function Hn(t) { return typeof t == "object" && t !== null && "subscribe" in t; } function nt(t) { const e = { subscribe(r) { let n = null, s = !1, a = !1, i = !1; function o() { if (n === null) { i = !0; return; } a || (a = !0, typeof n == "function" ? n() : n && n.unsubscribe()); } return n = t({ next(c) { s || r.next?.(c); }, error(c) { s || (s = !0, r.error?.(c), o()); }, complete() { s || (s = !0, r.complete?.(), o()); } }), i && o(), { unsubscribe: o }; }, pipe(...r) { return Fn(r)(e); } }; return e; } function Er(t) { return (e) => { let r = 0, n = null; const s = []; function a() { n || (n = e.subscribe({ next(o) { for (const c of s) c.next?.(o); }, error(o) { for (const c of s) c.error?.(o); }, complete() { for (const o of s) o.complete?.(); } })); } function i() { if (r === 0 && n) { const o = n; n = null, o.unsubscribe(); } } return { subscribe(o) { return r++, s.push(o), a(), { unsubscribe() { r--, i(); const c = s.findIndex((u) => u === o); c > -1 && s.splice(c, 1); } }; } }; }; } function Gn(t) { return (e) => ({ subscribe(r) { let n = 0; return e.subscribe({ next(a) { r.next?.(t(a, n++)); }, error(a) { r.error?.(a); }, complete() { r.complete?.(); } }); } }); } function Cr(t) { return (e) => ({ subscribe(r) { return e.subscribe({ next(n) { t.next?.(n), r.next?.(n); }, error(n) { t.error?.(n), r.error?.(n); }, complete() { t.complete?.(), r.complete?.(); } }); } }); } let Jn = class Rr extends Error { constructor(e) { super(e), this.name = "ObservableAbortError", Object.setPrototypeOf(this, Rr.prototype); } }; function Or(t) { let e; return { promise: new Promise((n, s) => { let a = !1; function i() { a || (a = !0, s(new Jn("This operation was aborted.")), o.unsubscribe()); } const o = t.subscribe({ next(c) { a = !0, n(c), i(); }, error(c) { a = !0, s(c), i(); }, complete() { a = !0, i(); } }); e = i; }), // eslint-disable-next-line @typescript-eslint/no-non-null-assertion abort: e }; } const Yn = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, isObservable: Hn, map: Gn, observable: nt, observableToPromise: Or, share: Er, tap: Cr }, Symbol.toStringTag, { value: "Module" })); function Sr(t) { return nt((e) => { function r(s = 0, a = t.op) { const i = t.links[s]; if (!i) throw new Error("No more links to execute - did you forget to add an ending link?"); return i({ op: a, next(c) { return r(s + 1, c); } }); } return r().subscribe(e); }); } function nr(t) { return Array.isArray(t) ? t : [ t ]; } function Xn(t) { return (e) => { const r = nr(t.true).map((s) => s(e)), n = nr(t.false).map((s) => s(e)); return (s) => nt((a) => { const i = t.condition(s.op) ? r : n; return Sr({ op: s.op, links: i }).subscribe(a); }); }; } function Pr(t) { const e = /* @__PURE__ */ Object.create(null); for (const r in t) { const n = t[r]; e[n] = r; } return e; } const st = { /** * Invalid JSON was received by the server. * An error occurred on the server while parsing the JSON text. */ PARSE_ERROR: -32700, /** * The JSON sent is not a valid Request object. */ BAD_REQUEST: -32600, // Internal JSON-RPC error INTERNAL_SERVER_ERROR: -32603, NOT_IMPLEMENTED: -32603, // Implementation specific errors UNAUTHORIZED: -32001, FORBIDDEN: -32003, NOT_FOUND: -32004, METHOD_NOT_SUPPORTED: -32005, TIMEOUT: -32008, CONFLICT: -32009, PRECONDITION_FAILED: -32012, PAYLOAD_TOO_LARGE: -32013, UNPROCESSABLE_CONTENT: -32022, TOO_MANY_REQUESTS: -32029, CLIENT_CLOSED_REQUEST: -32099 }; Pr(st); Pr(st); const Qn = { PARSE_ERROR: 400, BAD_REQUEST: 400, UNAUTHORIZED: 401, NOT_FOUND: 404, FORBIDDEN: 403, METHOD_NOT_SUPPORTED: 405, TIMEOUT: 408, CONFLICT: 409, PRECONDITION_FAILED: 412, PAYLOAD_TOO_LARGE: 413, UNPROCESSABLE_CONTENT: 422, TOO_MANY_REQUESTS: 429, CLIENT_CLOSED_REQUEST: 499, INTERNAL_SERVER_ERROR: 500, NOT_IMPLEMENTED: 501 }; function Kn(t) { return Qn[t] ?? 500; } function Ar(t) { return Kn(t.code); } const Nr = () => { }; function Ir(t, e) { return new Proxy(Nr, { get(n, s) { if (!(typeof s != "string" || s === "then")) return Ir(t, [ ...e, s ]); }, apply(n, s, a) { const i = e[e.length - 1] === "apply"; return t({ args: i ? a.length >= 2 ? a[1] : [] : a, path: i ? e.slice(0, -1) : e }); } }); } const Zt = (t) => Ir(t, []), Ut = (t) => new Proxy(Nr, { get(e, r) { if (!(typeof r != "string" || r === "then")) return t(r); } }); function es(t) { const { path: e, error: r, config: n } = t, { code: s } = t.error, a = { message: r.message, code: st[s], data: { code: s, httpStatus: Ar(r) } }; return n.isDev && typeof t.error.stack == "string" && (a.data.stack = t.error.stack), typeof e == "string" && (a.data.path = e), n.errorFormatter({ ...t, shape: a }); } function sr(t, e) { return "error" in e ? { ...e, error: t.transformer.output.serialize(e.error) } : "data" in e.result ? { ...e, result: { ...e.result, data: t.transformer.output.serialize(e.result.data) } } : e; } function ts(t, e) { return Array.isArray(e) ? e.map((r) => sr(t, r)) : sr(t, e); } function rs(t) { return !!t && !Array.isArray(t) && typeof t == "object"; } class ns extends Error { } function Wt(t) { if (t instanceof Error) return t; const e = typeof t; if (!(e === "undefined" || e === "function" || t === null)) { if (e !== "object") return new Error(String(t)); if (rs(t)) { const r = new ns(); for (const n in t) r[n] = t[n]; return r; } } } const ss = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, createFlatProxy: Ut, createRecursiveProxy: Zt, getCauseFromUnknown: Wt, getErrorShape: es, transformTRPCResponse: ts }, Symbol.toStringTag, { value: "Module" })); function ar(t) { return !!t && !Array.isArray(t) && typeof t == "object"; } function as(t) { return t instanceof jr || /** * @deprecated * Delete in next major */ t instanceof Error && t.name === "TRPCClientError"; } function is(t) { return ar(t) && ar(t.error) && typeof t.error.code == "number" && typeof t.error.message == "string"; } let jr = class Ee extends Error { static from(e, r = {}) { const n = e; return as(n) ? (r.meta && (n.meta = { ...n.meta, ...r.meta }), n) : is(n) ? new Ee(n.error.message, { ...r, result: n }) : n instanceof Error ? new Ee(n.message, { ...r, cause: Wt(n) }) : new Ee("Unknown error", { ...r, cause: n }); } constructor(e, r) { const n = r?.cause; super(e, { cause: n }), this.meta = r?.meta, this.cause = n, this.shape = r?.result?.error, this.data = r?.result?.error.data, this.name = "TRPCClientError", Object.setPrototypeOf(this, Ee.prototype); } }; function os(t) { return typeof FormData > "u" ? !1 : t instanceof FormData; } const mt = { css: { query: [ "72e3ff", "3fb0d8" ], mutation: [ "c5a3fc", "904dfc" ], subscription: [ "ff49e1", "d83fbe" ] }, ansi: { regular: { // Cyan background, black and white text respectively query: [ "\x1B[30;46m", "\x1B[97;46m" ], // Magenta background, black and white text respectively mutation: [ "\x1B[30;45m", "\x1B[97;45m" ], // Green background, black and white text respectively subscription: [ "\x1B[30;42m", "\x1B[97;42m" ] }, bold: { query: [ "\x1B[1;30;46m", "\x1B[1;97;46m" ], mutation: [ "\x1B[1;30;45m", "\x1B[1;97;45m" ], subscription: [ "\x1B[1;30;42m", "\x1B[1;97;42m" ] } } }; function cs(t) { const { direction: e, type: r, path: n, id: s, input: a } = t, i = [], o = []; if (t.colorMode === "ansi") { const [h, y] = mt.ansi.regular[r], [k, T] = mt.ansi.bold[r], A = "\x1B[0m"; return i.push(e === "up" ? h : y, e === "up" ? ">>" : "<<", r, e === "up" ? k : T, `#${s}`, n, A), e === "up" ? o.push({ input: t.input }) : o.push({ input: t.input, // strip context from result cause it's too noisy in terminal wihtout collapse mode result: "result" in t.result ? t.result.result : t.result, elapsedMs: t.elapsedMs }), { parts: i, args: o }; } const [c, u] = mt.css[r], d = ` background-color: #${e === "up" ? c : u}; color: ${e === "up" ? "black" : "white"}; padding: 2px; `; return i.push("%c", e === "up" ? ">>" : "<<", r, `#${s}`, `%c${n}%c`, "%O"), o.push(d, `${d}; font-weight: bold;`, `${d}; font-weight: normal;`), e === "up" ? o.push({ input: a, context: t.context }) : o.push({ input: a, result: t.result, elapsedMs: t.elapsedMs, context: t.context }), { parts: i, args: o }; } const us = ({ c: t = console, colorMode: e = "css" }) => (r) => { const n = r.input, s = os(n) ? Object.fromEntries(n) : n, { parts: a, args: i } = cs({ ...r, colorMode: e, input: s }), o = r.direction === "down" && r.result && (r.result instanceof Error || "error" in r.result.result) ? "error" : "log"; t[o].apply(null, [ a.join(" ") ].concat(i)); }; function ls(t = {}) { const { enabled: e = () => !0 } = t, r = t.colorMode ?? (typeof window > "u" ? "ansi" : "css"), { logger: n = us({ c: t.console, colorMode: r }) } = t; return () => ({ op: s, next: a }) => nt((i) => { e({ ...s, direction: "up" }) && n({ ...s, direction: "up" }); const o = Date.now(); function c(u) { const d = Date.now() - o; e({ ...s, direction: "down", result: u }) && n({ ...s, direction: "down", elapsedMs: d, result: u }); } return a(s).pipe(Cr({ next(u) { c(u); }, error(u) { c(u); } })).subscribe(i); }); } let ds = class { $request({ type: e, input: r, path: n, context: s = {} }) { return Sr({ links: this.links, op: { id: ++this.requestId, type: e, path: n, input: r, context: s } }).pipe(Er()); } requestAsPromise(e) { const r = this.$request(e), { promise: n, abort: s } = Or(r); return new Promise((i, o) => { e.signal?.addEventListener("abort", s), n.then((c) => { i(c.result.data); }).catch((c) => { o(jr.from(c)); }); }); } query(e, r, n) { return this.requestAsPromise({ type: "query", path: e, input: r, context: n?.context, signal: n?.signal }); } mutation(e, r, n) { return this.requestAsPromise({ type: "mutation", path: e, input: r, context: n?.context, signal: n?.signal }); } subscription(e, r, n) { return this.$request({ type: "subscription", path: e, input: r, context: n?.context }).subscribe({ next(a) { a.result.type === "started" ? n.onStarted?.() : a.result.type === "stopped" ? n.onStopped?.() : n.onData?.(a.result.data); }, error(a) { n.onError?.(a); }, complete() { n.onComplete?.(); } }); } constructor(e) { this.requestId = 0; const r = (() => { const n = e.transformer; return n ? "input" in n ? e.transformer : { input: n, output: n } : { input: { serialize: (s) => s, deserialize: (s) => s }, output: { serialize: (s) => s, deserialize: (s) => s } }; })(); this.runtime = { transformer: { serialize: (n) => r.input.serialize(n), deserialize: (n) => r.output.deserialize(n) }, combinedTransformer: r }, this.links = e.links.map((n) => n(this.runtime)); } }; const fs = { query: "query", mutate: "mutation", subscribe: "subscription" }, ps = (t) => fs[t]; function hs(t) { return Ut((e) => t.hasOwnProperty(e) ? t[e] : e === "__untypedClient" ? t : Zt(({ path: r, args: n }) => { const s = [ e, ...r ], a = ps(s.pop()), i = s.join("."); return t[a](i, ...n); })); } function ms(t) { const e = new ds(t); return hs(e); } function ys(t) { if (t instanceof ye || t instanceof Error && t.name === "TRPCError") return t; const e = new ye({ code: "INTERNAL_SERVER_ERROR", cause: t }); return t instanceof Error && t.stack && (e.stack = t.stack), e; } class ye extends Error { constructor(e) { const r = Wt(e.cause), n = e.message ?? r?.message ?? e.code; super(n, { cause: r }), this.code = e.code, this.name = "TRPCError", this.cause || (this.cause = r); } } function gs(t) { return "input" in t ? t : { input: t, output: t }; } const Se = { _default: !0, input: { serialize: (t) => t, deserialize: (t) => t }, output: { serialize: (t) => t, deserialize: (t) => t } }, Pe = ({ shape: t }) => t; function _s(t) { return Object.assign(/* @__PURE__ */ Object.create(null), t); } const vs = [ "query", "mutation", "subscription" ]; function bs(t) { return "router" in t._def; } const ws = { _ctx: null, _errorShape: null, _meta: null, queries: {}, mutations: {}, subscriptions: {}, errorFormatter: Pe, transformer: Se }, xs = [ /** * Then is a reserved word because otherwise we can't return a promise that returns a Proxy * since JS will think that `.then` is something that exists */ "then" ]; function Lr(t) { return function(r) { const n = new Set(Object.keys(r).filter((c) => xs.includes(c))); if (n.size > 0) throw new Error("Reserved words used in `router({})` call: " + Array.from(n).join(", ")); const s = _s({}); function a(c, u = "") { for (const [d, h] of Object.entries(c ?? {})) { const y = `${u}${d}`; if (bs(h)) { a(h._def.procedures, `${y}.`); continue; } if (s[y]) throw new Error(`Duplicate key: ${y}`); s[y] = h; } } a(r); const i = { _config: t, router: !0, procedures: s, ...ws, record: r, queries: Object.entries(s).filter((c) => c[1]._def.query).reduce((c, [u, d]) => ({ ...c, [u]: d }), {}), mutations: Object.entries(s).filter((c) => c[1]._def.mutation).reduce((c, [u, d]) => ({ ...c, [u]: d }), {}), subscriptions: Object.entries(s).filter((c) => c[1]._def.subscription).reduce((c, [u, d]) => ({ ...c, [u]: d }), {}) }, o = { ...r, _def: i, createCaller(c) { return $r()(o)(c); }, getErrorShape(c) { const { path: u, error: d } = c, { code: h } = c.error, y = { message: d.message, code: st[h], data: { code: h, httpStatus: Ar(d) } }; return t.isDev && typeof c.error.stack == "string" && (y.data.stack = c.error.stack), typeof u == "string" && (y.data.path = u), this._def._config.errorFormatter({ ...c, shape: y }); } }; return o; }; } function ks(t) { const { type: e, path: r } = t; if (!(r in t.procedures) || !t.procedures[r]?._def[e]) throw new ye({ code: "NOT_FOUND", message: `No "${e}"-procedure on path "${r}"` }); const n = t.procedures[r]; return n(t); } function $r() { return function(e) { const r = e._def; return function(s) { return Zt(({ path: i, args: o }) => { if (i.length === 1 && vs.includes(i[0])) return ks({ procedures: r.procedures, path: o[0], rawInput: o[1], ctx: s, type: i[0] }); const c = i.join("."), u = r.procedures[c]; let d = "query"; return u._def.mutation ? d = "mutation" : u._def.subscription && (d = "subscription"), u({ path: c, rawInput: o[0], ctx: s, type: d }); }); }; }; } const ir = typeof window > "u" || "Deno" in window || globalThis.process?.env?.NODE_ENV === "test" || !!globalThis.process?.env?.JEST_WORKER_ID || !!globalThis.process?.env?.VITEST_WORKER_ID; function or(t) { const e = t; if (typeof e == "function") return e; if (typeof e.parseAsync == "function") return e.parseAsync.bind(e); if (typeof e.parse == "function") return e.parse.bind(e); if (typeof e.validateSync == "function") return e.validateSync.bind(e); if (typeof e.create == "function") return e.create.bind(e); if (typeof e.assert == "function") return (r) => (e.assert(r), r); throw new Error("Could not find a validator fn"); } function Mr(t, ...e) { const r = Object.assign(/* @__PURE__ */ Object.create(null), t); for (const n of e) for (const s in n) { if (s in r && r[s] !== n[s]) throw new Error(`Duplicate key ${s}`); r[s] = n[s]; } return r; } function Ts() { function t(r) { return { _middlewares: r, unstable_pipe(n) { const s = "_middlewares" in n ? n._middlewares : [ n ]; return t([ ...r, ...s ]); } }; } function e(r) { return t([ r ]); } return e; } function cr(t) { return t && typeof t == "object" && !Array.isArray(t); } function Es(t) { const e = async ({ next: r, rawInput: n, input: s }) => { let a; try { a = await t(n); } catch (o) { throw new ye({ code: "BAD_REQUEST", cause: o }); } const i = cr(s) && cr(a) ? { ...s, ...a } : a; return r({ input: i }); }; return e._type = "input", e; } function Cs(t) { const e = async ({ next: r }) => { const n = await r(); if (!n.ok) return n; try { const s = await t(n.data); return { ...n, data: s }; } catch (s) { throw new ye({ message: "Output validation failed", code: "INTERNAL_SERVER_ERROR", cause: s }); } }; return e._type = "output", e; } const Dr = "middlewareMarker"; function fe(t, e) { const { middlewares: r = [], inputs: n, meta: s, ...a } = e; return Zr({ ...Mr(t, a), inputs: [ ...t.inputs, ...n ?? [] ], middlewares: [ ...t.middlewares, ...r ], meta: t.meta && s ? { ...t.meta, ...s } : s ?? t.meta }); } function Zr(t = {}) { const e = { inputs: [], middlewares: [], ...t }; return { _def: e, input(r) { const n = or(r); return fe(e, { inputs: [ r ], middlewares: [ Es(n) ] }); }, output(r) { const n = or(r); return fe(e, { output: r, middlewares: [ Cs(n) ] }); }, meta(r) { return fe(e, { meta: r }); }, /** * @deprecated * This functionality is deprecated and will be removed in the next major version. */ unstable_concat(r) { return fe(e, r._def); }, use(r) { const n = "_middlewares" in r ? r._middlewares : [ r ]; return fe(e, { middlewares: n }); }, query(r) { return yt({ ...e, query: !0 }, r); }, mutation(r) { return yt({ ...e, mutation: !0 }, r); }, subscription(r) { return yt({ ...e, subscription: !0 }, r); } }; } function yt(t, e) { const r = fe(t, { resolver: e, middlewares: [ async function(s) { const a = await e(s); return { marker: Dr, ok: !0, data: a, ctx: s.ctx }; } ] }); return Os(r._def); } const Rs = ` This is a client-only function. If you want to call this function on the server, see https://trpc.io/docs/server/server-side-calls `.trim(); function Os(t) { const e = async function(n) { if (!n || !("rawInput" in n)) throw new Error(Rs); const s = async (i = { index: 0, ctx: n.ctx }) => { try { const o = t.middlewares[i.index]; return await o({ ctx: i.ctx, type: n.type, path: n.path, rawInput: i.rawInput ?? n.rawInput, meta: t.meta, input: i.input, next(u) { const d = u; return s({ index: i.index + 1, ctx: d && "ctx" in d ? { ...i.ctx, ...d.ctx } : i.ctx, input: d && "input" in d ? d.input : i.input, rawInput: d && "rawInput" in d ? d.rawInput : i.rawInput }); } }); } catch (o) { return { ok: !1, error: ys(o), marker: Dr }; } }, a = await s(); if (!a) throw new ye({ code: "INTERNAL_SERVER_ERROR", message: "No result from middlewares - did you forget to `return next()`?" }); if (!a.ok) throw a.error; return a.data; }; return e._def = t, e.meta = t.meta, e; } function Ss(...t) { const e = Mr({}, ...t.map((a) => a._def.record)), r = t.reduce((a, i) => { if (i._def._config.errorFormatter && i._def._config.errorFormatter !== Pe) { if (a !== Pe && a !== i._def._config.errorFormatter) throw new Error("You seem to have several error formatters"); return i._def._config.errorFormatter; } return a; }, Pe), n = t.reduce((a, i) => { if (i._def._config.transformer && i._def._config.transformer !== Se) { if (a !== Se && a !== i._def._config.transformer) throw new Error("You seem to have several transformers"); return i._def._config.transformer; } return a; }, Se); return Lr({ errorFormatter: r, transformer: n, isDev: t.some((a) => a._def._config.isDev), allowOutsideOfServer: t.some((a) => a._def._config.allowOutsideOfServer), isServer: t.some((a) => a._def._config.isServer), $types: t[0]?._def._config.$types })(e); } class Je { context() { return new Je(); } meta() { return new Je(); } create(e) { return As()(e); } } const Ps = new Je(); function As() { return function(e) { const r = e?.errorFormatter ?? Pe, s = { transformer: gs(e?.transformer ?? Se), isDev: e?.isDev ?? globalThis.process?.env?.NODE_ENV !== "production", allowOutsideOfServer: e?.allowOutsideOfServer ?? !1, errorFormatter: r, isServer: e?.isServer ?? ir, /** * @internal */ $types: Ut((a) => { throw new Error(`Tried to access "$types.${a}" which is not available at runtime`); }) }; if (!(e?.isServer ?? ir) && e?.allowOutsideOfServer !== !0) throw new Error("You're trying to use @trpc/server in a non-server environment. This is not supported by default."); return { /** * These are just types, they can't be used * @internal */ _config: s, /** * Builder object for creating procedures * @see https://trpc.io/docs/server/procedures */ procedure: Zr({ meta: e?.defaultMeta }), /** * Create reusable middlewares * @see https://trpc.io/docs/server/middlewares */ middleware: Ts(), /** * Create a router * @see https://trpc.io/docs/server/routers */ router: Lr(s), /** * Merge Routers * @see https://trpc.io/docs/server/merging-routers */ mergeRouters: Ss, /** * Create a server-side caller for a router * @see https://trpc.io/docs/server/server-side-calls */ createCallerFactory: $r() }; }; } var Rt = {}, at = {}, be = {}, S = {}; const we = /* @__PURE__ */ kr(Yn); var qt = {}, Ur = we; function Wr(t) { return Ur.observable((e) => { function r(s = 0, a = t.op) { const i = t.links[s]; if (!i) throw new Error("No more links to execute - did you forget to add an ending link?"); return i({ op: a, next(c) { return r(s + 1, c); } }); } return r().subscribe(e); }); } function ur(t) { return Array.isArray(t) ? t : [ t ]; } function Ns(t) { return (e) => { const r = ur(t.true).map((s) => s(e)), n = ur(t.false).map((s) => s(e)); return (s) => Ur.observable((a) => { const i = t.condition(s.op) ? r : n; return Wr({ op: s.op, links: i }).subscribe(a); }); }; } qt.createChain = Wr; qt.splitLink = Ns; var xe = {}; const qr = /* @__PURE__ */ kr(ss); var ke = {}; function Ot(t) { return !!t && !Array.isArray(t) && typeof t == "object"; } function Is(t, e) { if ("error" in t) { const n = e.transformer.deserialize(t.error); return { ok: !1, error: { ...t, error: n } }; } return { ok: !0, result: { ...t.result, ...(!t.result.type || t.result.type === "data") && { type: "data", data: e.transformer.deserialize(t.result.data) } } }; } class gt extends Error { constructor() { super("Unable to transform response from server"); } } function js(t, e) { let r; try { r = Is(t, e); } catch { throw new gt(); } if (!r.ok && (!Ot(r.error.error) || typeof r.error.error.code != "number")) throw new gt(); if (r.ok && !Ot(r.result)) throw new gt(); return r; } ke.isObject = Ot; ke.transformResult = js; var Ls = qr, lr = ke; function $s(t) { return t instanceof zr || /** * @deprecated * Delete in next major */ t instanceof Error && t.name === "TRPCClientError"; } function Ms(t) { return lr.isObject(t) && lr.isObject(t.error) && typeof t.error.code == "number" && typeof t.error.message == "string"; } let zr = class Ce extends Error { static from(e, r = {}) { const n = e; return $s(n) ? (r.meta && (n.meta = { ...n.meta, ...r.meta }), n) : Ms(n) ? new Ce(n.error.message, { ...r, result: n }) : n instanceof Error ? new Ce(n.message, { ...r, cause: Ls.getCauseFromUnknown(n) }) : new Ce("Unknown error", { ...r, cause: n }); } constructor(e, r) { const n = r?.cause; super(e, { cause: n }), this.meta = r?.meta, this.cause = n, this.shape = r?.result?.error, this.data = r?.result?.error.data, this.name = "TRPCClientError", Object.setPrototypeOf(this, Ce.prototype); } }; xe.TRPCClientError = zr; var F = {}, Ds = xe; const dr = (t) => typeof t == "function"; function Br(t) { if (t) return t; if (typeof window < "u" && dr(window.fetch)) return window.fetch; if (typeof globalThis < "u" && dr(globalThis.fetch)) return globalThis.fetch; throw new Error("No fetch implementation found"); } function Zs(t) { return t || (typeof window < "u" && window.AbortController ? window.AbortController : typeof globalThis < "u" && globalThis.AbortController ? globalThis.AbortController : null); } function Us(t) { return { url: t.url.toString().replace(/\/$/, ""), fetch: t.fetch, AbortController: Zs(t.AbortController) }; } function Ws(t) { const e = {}; for (let r = 0; r < t.length; r++) { const n = t[r]; e[r] = n; } return e; } const qs = { query: "GET", mutation: "POST" }; function Vr(t) { return "input" in t ? t.runtime.transformer.serialize(t.input) : Ws(t.inputs.map((e) => t.runtime.transformer.serialize(e))); } const Fr = (t) => { let e = t.url + "/" + t.path; const r = []; if ("inputs" in t && r.push("batch=1"), t.type === "query") { const n = Vr(t); n !== void 0 && r.push(`input=${encodeURIComponent(JSON.stringify(n))}`); } return r.length && (e += "?" + r.join("&")), e; }, Hr = (t) => { if (t.type === "query") return; const e = Vr(t); return e !== void 0 ? JSON.stringify(e) : void 0; }, zs = (t) => Jr({ ...t, contentTypeHeader: "application/json", getUrl: Fr, getBody: Hr }); async function Gr(t, e) { const r = t.getUrl(t), n = t.getBody(t), { type: s } = t, a = await t.headers(); /* istanbul ignore if -- @preserve */ if (s === "subscription") throw new Error("Subscriptions should use wsLink"); const i = { ...t.contentTypeHeader ? { "content-type": t.contentTypeHeader } : {}, ...t.batchModeHeader ? { "trpc-batch-mode": t.batchModeHeader } : {}, ...a }; return Br(t.fetch)(r, { method: qs[s], signal: e?.signal, body: n, headers: i }); } function Jr(t) { const e = t.AbortController ? new t.AbortController() : null, r = {}; let n = !1; return { promise: new Promise((i, o) => { Gr(t, e).then((c) => (r.response = c, n = !0, c.json())).then((c) => { r.responseJSON = c, i({ json: c, meta: r }); }).catch((c) => { n = !0, o(Ds.TRPCClientError.from(c, { meta: r })); }); }), cancel: () => { n || e?.abort(); } }; } F.fetchHTTPResponse = Gr; F.getBody = Hr; F.getFetch = Br; F.getUrl = Fr; F.httpRequest = Jr; F.jsonHttpRequester = zs; F.resolveHTTPLinkOptions = Us; var zt = {}, Bs = we, Vs = ke, fr = xe, St = F; const _t = () => { throw new Error("Something went wrong. Please submit an issue at https://github.com/trpc/trpc/issues/new"); }; function vt(t) { let e = null, r = null; const n = () => { clearTimeout(r), r = null, e = null; }; function s(o) { const c = [ [] ]; let u = 0; for (; ; ) { const d = o[u]; if (!d) break; const h = c[c.length - 1]; if (d.aborted) { d.reject?.(new Error("Aborted")), u++; continue; } if (t.validate(h.concat(d).map((k) => k.key))) { h.push(d), u++; continue; } if (h.length === 0) { d.reject?.(new Error("Input is too big for a single dispatch")), u++; continue; } c.push([]); } return c; } function a() { const o = s(e); n(); for (const c of o) { if (!c.length) continue; const u = { items: c, cancel: _t }; for (const k of c) k.batch = u; const d = (k, T) => { const A = u.items[k]; A.resolve?.(T), A.batch = null, A.reject = null, A.resolve = null; }, { promise: h, cancel: y } = t.fetch(u.items.map((k) => k.key), d); u.cancel = y, h.then((k) => { for (let T = 0; T < k.length; T++) { const A = k[T]; d(T, A); } for (const T of u.items) T.reject?.(new Error("Missing result")), T.batch = null; }).catch((k) => { for (const T of u.items) T.reject?.(k), T.batch = null; }); } } function i(o) { const c = { aborted: !1, key: o, batch: null, resolve: _t, reject: _t }, u = new Promise((h, y) => { c.reject = y, c.resolve = h, e || (e = []), e.push(c); }); return r || (r = setTimeout(a)), { promise: u, cancel: () => { c.aborted = !0, c.batch?.items.every((h) => h.aborted) && (c.batch.cancel(), c.batch = null); } }; } return { load: i }; } function Yr(t) { return function(r) { const n = St.resolveHTTPLinkOptions(r), s = r.maxURLLength ?? 1 / 0; return (a) => { const i = (h) => { const y = (T) => { if (s === 1 / 0) return !0; const A = T.map((H) => H.path).join(","), le = T.map((H) => H.input); return St.getUrl({ ...n, runtime: a, type: h, path: A, inputs: le }).length <= s; }, k = t({ ...n, runtime: a, type: h, opts: r }); return { validate: y, fetch: k }; }, o = vt(i("query")), c = vt(i("mutation")), u = vt(i("subscription")), d = { query: o, subscription: u, mutation: c }; return ({ op: h }) => Bs.observable((y) => { const k = d[h.type], { promise: T, cancel: A } = k.load(h); let le; return T.then(($) => { le = $; const H = Vs.transformResult($.json, a); if (!H.ok) { y.error(fr.TRPCClientError.from(H.error, { meta: $.meta })); return; } y.next({ context: $.meta, result: H.result }), y.complete(); }).catch(($) => { y.error(fr.TRPCClientError.from($, { meta: le?.meta })); }), () => { A(); }; }); }; }; } const Fs = (t) => (e) => { const r = e.map((i) => i.path).join(","), n = e.map((i) => i.input), { promise: s, cancel: a } = St.jsonHttpRequester({ ...t, path: r, inputs: n, headers() { return t.opts.headers ? typeof t.opts.headers == "function" ? t.opts.headers({ opList: e }) : t.opts.headers : {}; } }); return { promise: s.then((i) => (Array.isArray(i.json) ? i.json : e.map(() => i.json)).map((u) => ({ meta: i.meta, json: u }))), cancel: a }; }, Hs = Yr(Fs); zt.createHTTPBatchLink = Yr; zt.httpBatchLink = Hs; var it = {}; Object.defineProperty(it, "__esModule", { value: !0 }); var Gs = we, Js = ke, pr = xe, Xr = F; function Qr(t) { return (e) => { const r = Xr.resolveHTTPLinkOptions(e); return (n) => ({ op: s }) => Gs.observable((a) => { const { path: i, input: o, type: c } = s, { promise: u, cancel: d } = t.requester({ ...r, runtime: n, type: c, path: i, input: o, headers() { return e.headers ? typeof e.headers == "function" ? e.headers({ op: s }) : e.headers : {}; } }); let h; return u.then((y) => { h = y.meta; const k = Js.transformResult(y.json, n); if (!k.ok) { a.error(pr.TRPCClientError.from(k.error, { meta: h })); return; } a.next({ context: y.meta, result: k.result }), a.complete(); }).catch((y) => { a.error(pr.TRPCClientError.from(y, { meta: h })); }), () => { d(); }; }); }; } const Ys = Qr({ requester: Xr.jsonHttpRequester }); it.httpLink = Ys; it.httpLinkFactory = Qr; var Bt = {}; Object.defineProperty(Bt, "__esModule", { value: !0 }); var hr = we; function Xs(t) { return typeof FormData > "u" ? !1 : t instanceof FormData; } const bt = { css: { query: [ "72e3ff", "3fb0d8" ], mutation: [ "c5a3fc", "904dfc" ], subscription: [ "ff49e1", "d83fbe" ] }, ansi: { regular: { // Cyan background, black and white text respectively query: [ "\x1B[30;46m", "\x1B[97;46m" ], // Magenta background, black and white text respectively mutation: [ "\x1B[30;45m", "\x1B[97;45m" ], // Green background, black and white text respectively subscription: [ "\x1B[30;42m", "\x1B[97;42m" ] }, bold: { query: [ "\x1B[1;30;46m", "\x1B[1;97;46m" ], mutation: [ "\x1B[1;30;45m", "\x1B[1;97;45m" ], subscription: [ "\x1B[1;30;42m", "\x1B[1;97;42m" ] } } }; function Qs(t) { const { direction: e, type: r, path: n, id: s, input: a } = t, i = [], o = []; if (t.colorMode === "ansi") { const [h, y] = bt.ansi.regular[r], [k, T] = bt.ansi.bold[r], A = "\x1B[0m"; return i.push(e === "up" ? h : y, e === "up" ? ">>" : "<<", r, e === "up" ? k : T, `#${s}`, n, A), e === "up" ? o.push({ input: t.input }) : o.push({ input: t.input, // strip context from result cause it's too noisy in terminal wihtout collapse mode result: "result" in t.result ? t.result.result : t.result, elapsedMs: t.elapsedMs }), { parts: i, args: o }; } const [c, u] = bt.css[r], d = ` background-color: #${e === "up" ? c : u}; color: ${e === "up" ? "black" : "white"}; padding: 2px; `; return i.push("%c", e === "up" ? ">>" : "<<", r, `#${s}`, `%c${n}%c`, "%O"), o.push(d, `${d}; font-weight: bold;`, `${d}; font-weight: normal;`), e === "up" ? o.push({ input: a, context: t.context }) : o.push({ input: a, result: t.result, elapsedMs: t.elapsedMs, context: t.context }), { parts: i, args: o }; } const Ks = ({ c: t = console, colorMode: e = "css" }) => (r) => { const n = r.input, s = Xs(n) ? Object.fromEntries(n) : n, { parts: a, args: i } = Qs({ ...r, colorMode: e, input: s }), o = r.direction === "down" && r.result && (r.result instanceof Error || "error" in r.result.result) ? "error" : "log"; t[o].apply(null, [ a.join(" ") ].concat(i)); }; function ea(t = {}) { const { enabled: e = () => !0 } = t, r = t.colorMode ?? (typeof window > "u" ? "ansi" : "css"), { logger: n = Ks({ c: t.console, colorMode: r }) } = t; return () => ({ op: s, next: a }) => hr.observable((i) => { e({ ...s, direction: "up" }) && n({ ...s, direction: "up" }); const o = Date.now(); function c(u) { const d = Date.now() - o; e({ ...s, direction: "down", result: u }) && n({ ...s, direction: "down", elapsedMs: d, result: u }); } return a(s).pipe(hr.tap({ next(u) { c(u); }, error(u) { c(u); } })).subscribe(i); }); } Bt.loggerLink = ea; var ot = {}; Object.defineProperty(ot, "__esModule", { value: !0 }); var ta = we, ra = ke, Kr = xe; /* istanbul ignore next -- @preserve */ const na = (t) => t === 0 ? 0 : Math.min(1e3 * 2 ** t, 3e4); function sa(t) { const { url: e, WebSocket: r = WebSocket, retryDelayMs: n = na, onOpen: s, onClose: a } = t; /* istanbul ignore next -- @preserve */ if (!r) throw new Error("No WebSocket implementation found - you probably don't want to use this on the server, but if you do you need to pass a `WebSocket`-ponyfill"); let i = []; const o = /* @__PURE__ */ Object.create(null); let c = 0, u = null, d = null, h = Qt(), y = "connecting"; function k() { y !== "open" || u || (u = setTimeout(() => { u = null, i.length === 1 ? h.send(JSON.stringify(i.pop())) : h.send(JSON.stringify(i)), i = []; })); } function T() { if (d !== null || y === "closed") return; const R = n(c++); le(R); } function A() { y = "connecting"; const R = h; h = Qt(), $(R); } function le(R) { d || (y = "connecting", d = setTimeout(A, R)); } function $(R) { Object.values(o).some((de) => de.ws === R) || R.close(); } function H() { Object.values(o).forEach((R) => { R.type === "subscription" && R.callbacks.complete(); }); } function Xt(R) { i.some((P) => P.id === R.op.id) || Kt(R.op, R.callbacks); } function Qt() { const R = typeof e == "function" ? e() : e, P = new r(R); clearTimeout(d), d = null, P.addEventListener("open", () => { /* istanbul ignore next -- @preserve */ P === h && (c = 0, y = "open", s?.(), k()); }), P.addEventListener("error", () => { P === h && T(); }); const de = (j) => { if (j.method === "reconnect" && P === h) { y === "open" && a?.(), A(); for (const E of Object.values(o)) E.type === "subscription" && Xt(E); } }, pt = (j) => { const E = j.id !== null && o[j.id]; if (E) { if (E.callbacks.next?.(j), E.ws !== h && P === h) { const G = E.ws; E.ws = h, $(G); } "result" in j && j.result.type === "stopped" && P === h && E.callbacks.complete(); } }; return P.addEventListener("message", ({ data: j }) => { const E = JSON.parse(j); "method" in E ? de(E) : pt(E), (P !== h || y === "closed") && $(P); }), P.addEventListener("close", ({ code: j }) => { y === "open" && a?.({ code: j }), h === P && T(); for (const [E, G] of Object.entries(o)) if (G.ws === P) { if (y === "closed") { delete o[E], G.callbacks.complete?.(); continue; } G.type === "subscription" ? Xt(G) : (delete o[E], G.callbacks.error?.(Kr.TRPCClientError.from(new Vt("WebSocket closed prematurely")))); } }), P; } function Kt(R, P) { const { type: de, input: pt, path: j, id: E } = R, G = { id: E, method: de, params: { input: pt, path: j } }; return o[E] = { ws: h, type: de, callbacks: P, op: R }, i.push(G), k(), () => { const Cn = o[E]?.callbacks; delete o[E], i = i.filter((Rn) => Rn.id !== E), Cn?.complete?.(), h.readyState === r.OPEN && R.type === "subscription" && (i.push({ id: E, method: "subscription.stop" }), k()); }; } return { close: () => { y = "closed", a?.(), H(), $(h), clearTimeout(d), d = null; }, request: Kt, getConnection() { return h; } }; } class Vt extends Error { constructor(e) { super(e), this.name = "TRPCWebSocketClosedError", Object.setPrototypeOf(this, Vt.prototype); } } function aa(t) { return (e) => { const { client: r } = t; return ({ op: n }) => ta.observable((s) => { const { type: a, path: i, id: o, context: c } = n, u = e.transformer.serialize(n.input), d = r.request({ type: a, path: i, input: u, id: o, context: c }, { error(h) { s.error(h), d(); }, complete() { s.complete(); }, next(h) { const y = ra.transformResult(h, e); if (!y.ok) { s.error(Kr.TRPCClientError.from(y.error)); return; } s.next({ result: y.result }), n.type !== "subscription" && (d(), s.complete()); } }); return () => { d(); }; }); }; } ot.createWSClient = sa; ot.wsLink = aa; Object.defineProperty(S, "__esModule", { value: !0 }); var mr = we, en = qt, tn = xe, yr = qr, Ae = F, rn = zt, Ft = it, ia = Bt, nn = ot; class ct { $request({ type: e, input: r, path: n, context: s = {} }) { return en.createChain({ links: this.links, op: { id: ++this.requestId, type: e, path: n, input: r, context: s } }).pipe(mr.share()); } requestAsPromise(e) { const r = this.$request(e), { promise: n, abort: s } = mr.observableToPromise(r); return new Promise((i, o) => { e.signal?.addEventListener("abort", s), n.then((c) => { i(c.result.data); }).catch((c) => { o(tn.TRPCClientError.from(c)); }); }); } query(e, r, n) { return this.requestAsPromise({ type: "query", path: e, input: r, context: n?.context, signal: n?.signal }); } mutation(e, r, n) { return this.requestAsPromise({ type: "mutation", path: e, input: r, context: n?.context, signal: n?.signal }); } subscription(e, r, n) { return this.$request({ type: "subscription", path: e, input: r, context: n?.context }).subscribe({ next(a) { a.result.type === "started" ? n.onStarted?.() : a.result.type === "stopped" ? n.onStopped?.() : n.onData?.(a.result.data); }, error(a) { n.onError?.(a); }, complete() { n.onComplete?.(); } }); } constructor(e) { this.requestId = 0; const r = (() => { const n = e.transformer; return n ? "input" in n ? e.transformer : { input: n, output: n } : { input: { serialize: (s) => s, deserialize: (s) => s }, output: { serialize: (s) => s, deserialize: (s) => s } }; })(); this.runtime = { transformer: { serialize: (n) => r.input.serialize(n), deserialize: (n) => r.output.deserialize(n) }, combinedTransformer: r }, this.links = e.links.map((n) => n(this.runtime)); } } function oa(t) { return new ct(t); } function ca(t) { return new ct(t); } const ua = { query: "query", mutate: "mutation", subscribe: "subscription" }, sn = (t) => ua[t]; function an(t) { return yr.createFlatProxy((e) => t.hasOwnProperty(e) ? t[e] : e === "__untypedClient" ? t : yr.createRecursiveProxy(({ path: r, args: n }) => { const s = [ e, ...r ], a = sn(s.pop()), i = s.join("."); return t[a](i, ...n); })); } function la(t) { const e = new ct(t); return an(e); } function da(t) { return t.__untypedClient; } function fa(t) { if (t) return t; if (typeof window < "u" && window.TextDecoder) return new window.TextDecoder(); if (typeof globalThis < "u" && globalThis.TextDecoder) return new globalThis.TextDecoder(); throw new Error("No TextDecoder implementation found"); } async function pa(t) { const e = t.parse ?? JSON.parse, r = (n) => { if (t.signal?.aborted || !n || n === "}") return; const s = n.indexOf(":"), a = n.substring(2, s - 1), i = n.substring(s + 1); t.onSingle(Number(a), e(i)); }; await ha(t.readableStream, r, t.textDecoder); } async function ha(t, e, r) { let n = ""; const s = (a) => { const o = r.decode(a).split(` `); if (o.length === 1) n += o[0]; else if (o.length > 1) { e(n + o[0]); for (let c = 1; c < o.length - 1; c++) e(o[c]); n = o[o.length - 1]; } }; "getReader" in t ? await ya(t, s) : await ma(t, s), e(n); } function ma(t, e) {