@authhero/drizzle 0.59.0 → 0.60.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2407,7 +2407,7 @@ function qn(e) {
2407
2407
  };
2408
2408
  }
2409
2409
  //#endregion
2410
- //#region ../../node_modules/.pnpm/hono@4.12.28/node_modules/hono/dist/http-exception.js
2410
+ //#region ../../node_modules/.pnpm/hono@4.12.29/node_modules/hono/dist/http-exception.js
2411
2411
  var Jn = class extends Error {
2412
2412
  res;
2413
2413
  status;
@@ -13947,7 +13947,7 @@ var M_ = /* @__PURE__ */ a({
13947
13947
  xor: () => rg
13948
13948
  });
13949
13949
  //#endregion
13950
- //#region ../../node_modules/.pnpm/@hono+zod-openapi@1.4.0_hono@4.12.28_zod@4.4.3/node_modules/@hono/zod-openapi/dist/index.js
13950
+ //#region ../../node_modules/.pnpm/@hono+zod-openapi@1.4.0_hono@4.12.29_zod@4.4.3/node_modules/@hono/zod-openapi/dist/index.js
13951
13951
  Tr(rl()), _r(M_);
13952
13952
  //#endregion
13953
13953
  //#region ../adapter-interfaces/dist/adapter-interfaces.mjs
@@ -18550,9 +18550,121 @@ function fS(e) {
18550
18550
  };
18551
18551
  }
18552
18552
  //#endregion
18553
+ //#region src/adapters/outbox.ts
18554
+ Je();
18555
+ function pS(e) {
18556
+ return {
18557
+ ...e,
18558
+ payload: N(e.payload, {})
18559
+ };
18560
+ }
18561
+ function mS(e, t, n, r) {
18562
+ return e.insert(A).values({
18563
+ id: t,
18564
+ tenant_id: n,
18565
+ event_type: r.event_type,
18566
+ log_type: r.log_type,
18567
+ aggregate_type: r.aggregate_type ?? r.target?.type,
18568
+ aggregate_id: r.aggregate_id ?? r.target?.id,
18569
+ payload: JSON.stringify({
18570
+ ...r,
18571
+ id: t
18572
+ }),
18573
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
18574
+ processed_at: null,
18575
+ retry_count: 0,
18576
+ next_retry_at: null,
18577
+ error: null,
18578
+ claimed_by: null,
18579
+ claim_expires_at: null
18580
+ });
18581
+ }
18582
+ function hS(e) {
18583
+ return {
18584
+ async create(t, n) {
18585
+ let r = qe();
18586
+ return await mS(e, r, t, n), r;
18587
+ },
18588
+ async getByIds(t) {
18589
+ return t.length === 0 ? [] : (await e.select().from(A).where(Fe(A.id, t)).all()).map(pS);
18590
+ },
18591
+ async getUnprocessed(t) {
18592
+ let n = (/* @__PURE__ */ new Date()).toISOString();
18593
+ return (await e.select().from(A).where(g(Ie(A.processed_at), Ae(Ie(A.next_retry_at), Pe(A.next_retry_at, n)), Ae(Ie(A.claimed_by), Pe(A.claim_expires_at, n)))).orderBy(A.created_at, A.id).limit(t).all()).map(pS);
18594
+ },
18595
+ async claimEvents(t, n, r) {
18596
+ if (t.length === 0) return [];
18597
+ let i = (/* @__PURE__ */ new Date()).toISOString(), a = new Date(Date.now() + r).toISOString();
18598
+ return await e.update(A).set({
18599
+ claimed_by: n,
18600
+ claim_expires_at: a
18601
+ }).where(g(Fe(A.id, t), Ie(A.processed_at), Ae(Ie(A.claimed_by), Pe(A.claim_expires_at, i)))), (await e.select({ id: A.id }).from(A).where(g(Fe(A.id, t), h(A.claimed_by, n))).all()).map((e) => e.id);
18602
+ },
18603
+ async markProcessed(t) {
18604
+ t.length !== 0 && await e.update(A).set({ processed_at: (/* @__PURE__ */ new Date()).toISOString() }).where(Fe(A.id, t));
18605
+ },
18606
+ async markRetry(t, n, r) {
18607
+ await e.update(A).set({
18608
+ error: n,
18609
+ next_retry_at: r,
18610
+ retry_count: m`${A.retry_count} + 1`,
18611
+ claimed_by: null,
18612
+ claim_expires_at: null
18613
+ }).where(h(A.id, t));
18614
+ },
18615
+ async cleanup(t) {
18616
+ return (await e.delete(A).where(g(m`${A.processed_at} IS NOT NULL`, Pe(A.processed_at, t))).returning()).length;
18617
+ },
18618
+ async deadLetter(t, n) {
18619
+ let r = (/* @__PURE__ */ new Date()).toISOString();
18620
+ await e.update(A).set({
18621
+ processed_at: r,
18622
+ dead_lettered_at: r,
18623
+ final_error: n
18624
+ }).where(h(A.id, t));
18625
+ },
18626
+ async listFailed(t, n = {}) {
18627
+ let { page: r = 0, per_page: i = 50, include_totals: a = !1 } = n, o = (await e.select().from(A).where(g(h(A.tenant_id, t), Le(A.dead_lettered_at))).orderBy(v(A.dead_lettered_at), _(A.id)).offset(r * i).limit(i).all()).map((e) => ({
18628
+ ...N(e.payload, {}),
18629
+ id: e.id,
18630
+ created_at: e.created_at,
18631
+ processed_at: e.processed_at,
18632
+ retry_count: e.retry_count,
18633
+ next_retry_at: e.next_retry_at,
18634
+ error: e.error,
18635
+ dead_lettered_at: e.dead_lettered_at,
18636
+ final_error: e.final_error
18637
+ })), s = o.length;
18638
+ if (a) {
18639
+ let [n] = await e.select({ total: Be() }).from(A).where(g(h(A.tenant_id, t), Le(A.dead_lettered_at)));
18640
+ s = Number(n?.total ?? o.length);
18641
+ }
18642
+ return {
18643
+ events: o,
18644
+ start: r * i,
18645
+ limit: i,
18646
+ length: s
18647
+ };
18648
+ },
18649
+ async replay(t, n) {
18650
+ return (await e.update(A).set({
18651
+ processed_at: null,
18652
+ dead_lettered_at: null,
18653
+ final_error: null,
18654
+ retry_count: 0,
18655
+ next_retry_at: null,
18656
+ error: null
18657
+ }).where(g(h(A.id, t), h(A.tenant_id, n), Le(A.dead_lettered_at))).returning()).length > 0;
18658
+ }
18659
+ };
18660
+ }
18661
+ //#endregion
18553
18662
  //#region src/adapters/users.ts
18554
18663
  Je();
18555
- var pS = [
18664
+ function gS(e, t, n) {
18665
+ return (n?.outboxEvents ?? []).map((n) => mS(e, n.id, t, n));
18666
+ }
18667
+ var _S = [
18556
18668
  "user_id",
18557
18669
  "email",
18558
18670
  "email_verified",
@@ -18574,23 +18686,23 @@ var pS = [
18574
18686
  "login_count",
18575
18687
  "created_at",
18576
18688
  "updated_at"
18577
- ], mS = [
18689
+ ], vS = [
18578
18690
  "email",
18579
18691
  "name",
18580
18692
  "phone_number",
18581
18693
  "user_id"
18582
- ], hS = /* @__PURE__ */ new Set([
18694
+ ], yS = /* @__PURE__ */ new Set([
18583
18695
  "last_login",
18584
18696
  "last_ip",
18585
18697
  "login_count"
18586
- ]), gS = Te(w), _S = Te(Jt), vS = Object.fromEntries(pS.map((e) => [e, e === "login_count" ? {
18698
+ ]), bS = Te(w), xS = Te(Jt), SS = Object.fromEntries(_S.map((e) => [e, e === "login_count" ? {
18587
18699
  coalesce: Jt.login_count,
18588
18700
  defaultValue: 0
18589
- } : hS.has(e) ? _S[e] : gS[e]]));
18590
- function yS() {
18701
+ } : yS.has(e) ? xS[e] : bS[e]]));
18702
+ function CS() {
18591
18703
  return g(h(Jt.tenant_id, w.tenant_id), h(Jt.user_id, w.user_id));
18592
18704
  }
18593
- function bS(e, t) {
18705
+ function wS(e, t) {
18594
18706
  return {
18595
18707
  ...e,
18596
18708
  last_login: t?.last_login,
@@ -18598,7 +18710,7 @@ function bS(e, t) {
18598
18710
  login_count: t?.login_count ?? 0
18599
18711
  };
18600
18712
  }
18601
- function xS(e, t) {
18713
+ function TS(e, t) {
18602
18714
  let n = {
18603
18715
  connection: e.connection,
18604
18716
  provider: e.provider,
@@ -18611,8 +18723,8 @@ function xS(e, t) {
18611
18723
  ...typeof e.profileData == "string" ? N(e.profileData, {}) : {}
18612
18724
  }, n;
18613
18725
  }
18614
- function SS(e, t = []) {
18615
- let { tenant_id: n, app_metadata: r, user_metadata: i, address: a, email_verified: o, phone_verified: s, is_social: c, linked_to: l, profileData: u, ...d } = e, f = xS(e, !0), p = t.map((e) => xS(e, !1));
18726
+ function ES(e, t = []) {
18727
+ let { tenant_id: n, app_metadata: r, user_metadata: i, address: a, email_verified: o, phone_verified: s, is_social: c, linked_to: l, profileData: u, ...d } = e, f = TS(e, !0), p = t.map((e) => TS(e, !1));
18616
18728
  return M({
18617
18729
  ...d,
18618
18730
  email: e.email || "",
@@ -18625,9 +18737,9 @@ function SS(e, t = []) {
18625
18737
  identities: [f, ...p]
18626
18738
  });
18627
18739
  }
18628
- function CS(e) {
18629
- let t = async (t, n) => {
18630
- let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
18740
+ function DS(e) {
18741
+ let t = async (t, n, r) => {
18742
+ let i = (/* @__PURE__ */ new Date()).toISOString(), a = {
18631
18743
  user_id: n.user_id,
18632
18744
  tenant_id: t,
18633
18745
  email: n.email,
@@ -18657,32 +18769,34 @@ function CS(e) {
18657
18769
  gender: n.gender,
18658
18770
  birthdate: n.birthdate,
18659
18771
  zoneinfo: n.zoneinfo,
18660
- created_at: n.created_at || r,
18661
- updated_at: n.updated_at || r
18662
- }, a = n.password ? qe() : void 0, o = n.last_login !== void 0 || n.last_ip !== void 0 || n.login_count !== void 0;
18772
+ created_at: n.created_at || i,
18773
+ updated_at: n.updated_at || i
18774
+ }, o = n.password ? qe() : void 0, s = n.last_login !== void 0 || n.last_ip !== void 0 || n.login_count !== void 0;
18663
18775
  try {
18664
- let s = [e.insert(w).values(i)];
18665
- o && s.push(e.insert(Jt).values({
18776
+ let c = [e.insert(w).values(a)];
18777
+ s && c.push(e.insert(Jt).values({
18666
18778
  tenant_id: t,
18667
18779
  user_id: n.user_id,
18668
18780
  last_login: n.last_login,
18669
18781
  last_ip: n.last_ip,
18670
18782
  login_count: n.login_count ?? 0
18671
- })), n.password && a && s.push(e.insert(qt).values({
18672
- id: a,
18783
+ })), n.password && o && c.push(e.insert(qt).values({
18784
+ id: o,
18673
18785
  tenant_id: t,
18674
18786
  user_id: n.user_id,
18675
18787
  password: n.password.hash || n.password,
18676
18788
  algorithm: n.password.algorithm || "bcrypt",
18677
18789
  is_current: 1,
18678
- created_at: r,
18679
- updated_at: r
18680
- })), s.length > 1 ? await Un(e, s) : await e.insert(w).values(i);
18790
+ created_at: i,
18791
+ updated_at: i
18792
+ }));
18793
+ for (let n of gS(e, t, r)) c.push(n);
18794
+ c.length > 1 ? await Un(e, c) : await e.insert(w).values(a);
18681
18795
  } catch (e) {
18682
18796
  throw e?.message?.includes("UNIQUE constraint") || e?.message?.includes("AlreadyExists") ? new Jn(409, { message: "User already exists" }) : (console.error("User upsert failed:", e?.code, e?.message), new Jn(500, { message: "Internal server error" }));
18683
18797
  }
18684
- return SS({
18685
- ...i,
18798
+ return ES({
18799
+ ...a,
18686
18800
  last_login: n.last_login,
18687
18801
  last_ip: n.last_ip,
18688
18802
  login_count: n.login_count ?? 0
@@ -18692,13 +18806,13 @@ function CS(e) {
18692
18806
  create: t,
18693
18807
  rawCreate: t,
18694
18808
  async get(t, n) {
18695
- let r = await e.select().from(w).leftJoin(Jt, yS()).where(g(h(w.tenant_id, t), h(w.user_id, n))).get();
18809
+ let r = await e.select().from(w).leftJoin(Jt, CS()).where(g(h(w.tenant_id, t), h(w.user_id, n))).get();
18696
18810
  if (!r) return null;
18697
18811
  let i = await e.select().from(w).where(g(h(w.tenant_id, t), h(w.linked_to, n))).all();
18698
- return SS(bS(r.users, r.user_activity), i);
18812
+ return ES(wS(r.users, r.user_activity), i);
18699
18813
  },
18700
- async update(t, n, r) {
18701
- let i = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
18814
+ async update(t, n, r, i) {
18815
+ let a = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
18702
18816
  for (let e of [
18703
18817
  "email",
18704
18818
  "given_name",
@@ -18720,8 +18834,10 @@ function CS(e) {
18720
18834
  "gender",
18721
18835
  "birthdate",
18722
18836
  "zoneinfo"
18723
- ]) r[e] !== void 0 && (i[e] = r[e]);
18724
- return r.email_verified !== void 0 && (i.email_verified = r.email_verified), r.phone_verified !== void 0 && (i.phone_verified = r.phone_verified), r.is_social !== void 0 && (i.is_social = r.is_social), r.app_metadata !== void 0 && (i.app_metadata = JSON.stringify(r.app_metadata)), r.user_metadata !== void 0 && (i.user_metadata = JSON.stringify(r.user_metadata)), r.address !== void 0 && (i.address = JSON.stringify(r.address)), r.profileData !== void 0 && (i.profileData = JSON.stringify(r.profileData)), (await e.update(w).set(i).where(g(h(w.tenant_id, t), h(w.user_id, n))).returning()).length === 0 ? !1 : ((r.last_login !== void 0 || r.last_ip !== void 0 || r.login_count !== void 0) && await fS(e).upsert(t, n, {
18837
+ ]) r[e] !== void 0 && (a[e] = r[e]);
18838
+ r.email_verified !== void 0 && (a.email_verified = r.email_verified), r.phone_verified !== void 0 && (a.phone_verified = r.phone_verified), r.is_social !== void 0 && (a.is_social = r.is_social), r.app_metadata !== void 0 && (a.app_metadata = JSON.stringify(r.app_metadata)), r.user_metadata !== void 0 && (a.user_metadata = JSON.stringify(r.user_metadata)), r.address !== void 0 && (a.address = JSON.stringify(r.address)), r.profileData !== void 0 && (a.profileData = JSON.stringify(r.profileData));
18839
+ let o = e.update(w).set(a).where(g(h(w.tenant_id, t), h(w.user_id, n))).returning(), s = gS(e, t, i), c;
18840
+ return c = s.length > 0 ? (await Un(e, [o, ...s]))[0] : await o, !Array.isArray(c) || c.length === 0 ? !1 : ((r.last_login !== void 0 || r.last_ip !== void 0 || r.login_count !== void 0) && await fS(e).upsert(t, n, {
18725
18841
  last_login: r.last_login,
18726
18842
  last_ip: r.last_ip,
18727
18843
  login_count: r.login_count
@@ -18730,25 +18846,25 @@ function CS(e) {
18730
18846
  async list(t, n) {
18731
18847
  let { page: r = 0, per_page: i = 50, include_totals: a = !1, sort: o, q: s } = n || {}, c = [h(w.tenant_id, t), Ie(w.linked_to)];
18732
18848
  if (s) {
18733
- let e = In(s, pS);
18849
+ let e = In(s, _S);
18734
18850
  if (e) {
18735
- let t = Ln(vS, e, mS);
18851
+ let t = Ln(SS, e, vS);
18736
18852
  t && c.push(t);
18737
18853
  }
18738
18854
  }
18739
- let l = g(...c), u = e.select().from(w).leftJoin(Jt, yS()).where(l).$dynamic();
18855
+ let l = g(...c), u = e.select().from(w).leftJoin(Jt, CS()).where(l).$dynamic();
18740
18856
  if (o?.sort_by) {
18741
- let e = vS[o.sort_by];
18857
+ let e = SS[o.sort_by];
18742
18858
  if (e) {
18743
18859
  let t = Pn(e) ? Fn(e) : e;
18744
18860
  u = u.orderBy(o.sort_order === "desc" ? v(t) : _(t));
18745
18861
  }
18746
18862
  }
18747
- let d = (await u.offset(r * i).limit(i)).map((e) => bS(e.users, e.user_activity)), f = d.map((e) => e.user_id), p = [];
18863
+ let d = (await u.offset(r * i).limit(i)).map((e) => wS(e.users, e.user_activity)), f = d.map((e) => e.user_id), p = [];
18748
18864
  f.length > 0 && (p = await e.select().from(w).where(g(h(w.tenant_id, t), Fe(w.linked_to, f))));
18749
- let ee = d.map((e) => SS(e, p.filter((t) => t.linked_to === e.user_id)));
18865
+ let ee = d.map((e) => ES(e, p.filter((t) => t.linked_to === e.user_id)));
18750
18866
  if (!a) return { users: ee };
18751
- let [te] = await e.select({ count: Be() }).from(w).leftJoin(Jt, yS()).where(l);
18867
+ let [te] = await e.select({ count: Be() }).from(w).leftJoin(Jt, CS()).where(l);
18752
18868
  return {
18753
18869
  users: ee,
18754
18870
  start: r * i,
@@ -18756,15 +18872,17 @@ function CS(e) {
18756
18872
  length: Number(te?.count ?? 0)
18757
18873
  };
18758
18874
  },
18759
- async remove(t, n) {
18760
- let r = (await e.select({ user_id: w.user_id }).from(w).where(g(h(w.tenant_id, t), h(w.linked_to, n)))).map((e) => e.user_id), i = [n, ...r], a = await Un(e, [
18761
- e.delete(En).where(g(h(En.tenant_id, t), Fe(En.user_id, i))),
18762
- e.delete(qt).where(g(h(qt.tenant_id, t), Fe(qt.user_id, i))),
18763
- e.delete(Jt).where(g(h(Jt.tenant_id, t), Fe(Jt.user_id, i))),
18764
- e.delete(w).where(g(h(w.tenant_id, t), Fe(w.user_id, r))),
18875
+ async remove(t, n, r) {
18876
+ let i = await e.select({ user_id: w.user_id }).from(w).where(g(h(w.tenant_id, t), Ae(h(w.user_id, n), h(w.linked_to, n)))), a = i.some((e) => e.user_id === n), o = i.map((e) => e.user_id).filter((e) => e !== n), s = [n, ...o], c = [
18877
+ e.delete(En).where(g(h(En.tenant_id, t), Fe(En.user_id, s))),
18878
+ e.delete(qt).where(g(h(qt.tenant_id, t), Fe(qt.user_id, s))),
18879
+ e.delete(Jt).where(g(h(Jt.tenant_id, t), Fe(Jt.user_id, s))),
18880
+ e.delete(w).where(g(h(w.tenant_id, t), Fe(w.user_id, o))),
18765
18881
  e.delete(w).where(g(h(w.tenant_id, t), h(w.user_id, n))).returning()
18766
- ]), o = a[a.length - 1];
18767
- return Array.isArray(o) && o.length > 0;
18882
+ ], l = c.length - 1;
18883
+ if (a) for (let n of gS(e, t, r)) c.push(n);
18884
+ let u = (await Un(e, c))[l];
18885
+ return Array.isArray(u) && u.length > 0;
18768
18886
  },
18769
18887
  async unlink(t, n, r, i) {
18770
18888
  let a = `${r}|${i}`;
@@ -18774,7 +18892,7 @@ function CS(e) {
18774
18892
  }
18775
18893
  //#endregion
18776
18894
  //#region src/adapters/userRoles.ts
18777
- function wS(e) {
18895
+ function OS(e) {
18778
18896
  return {
18779
18897
  async create(t, n, r, i) {
18780
18898
  try {
@@ -18814,7 +18932,7 @@ function wS(e) {
18814
18932
  //#endregion
18815
18933
  //#region src/adapters/userOrganizations.ts
18816
18934
  Je();
18817
- function TS(e) {
18935
+ function kS(e) {
18818
18936
  return {
18819
18937
  async create(t, n) {
18820
18938
  let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
@@ -18891,19 +19009,19 @@ function TS(e) {
18891
19009
  }
18892
19010
  //#endregion
18893
19011
  //#region src/adapters/stats.ts
18894
- var ES = ["s"], DS = ["pwd_leak"];
18895
- function OS(e) {
19012
+ var AS = ["s"], jS = ["pwd_leak"];
19013
+ function MS(e) {
18896
19014
  return /^\d{8}$/.test(e) ? `${e.slice(0, 4)}-${e.slice(4, 6)}-${e.slice(6, 8)}` : e;
18897
19015
  }
18898
- function kS(e) {
19016
+ function NS(e) {
18899
19017
  return {
18900
19018
  async getDaily(t, n) {
18901
- let r = /* @__PURE__ */ new Date(), i = n?.from ? OS(n.from) : (/* @__PURE__ */ new Date(r.getTime() - 720 * 60 * 60 * 1e3)).toISOString().split("T")[0], a = n?.to ? OS(n.to) : r.toISOString().split("T")[0];
19019
+ let r = /* @__PURE__ */ new Date(), i = n?.from ? MS(n.from) : (/* @__PURE__ */ new Date(r.getTime() - 720 * 60 * 60 * 1e3)).toISOString().split("T")[0], a = n?.to ? MS(n.to) : r.toISOString().split("T")[0];
18902
19020
  return (await e.select({
18903
19021
  date: m`substr(${k.date}, 1, 10)`.as("date"),
18904
- logins: m`SUM(CASE WHEN ${k.type} IN (${m.join(ES.map((e) => m`${e}`), m`, `)}) THEN 1 ELSE 0 END)`.as("logins"),
19022
+ logins: m`SUM(CASE WHEN ${k.type} IN (${m.join(AS.map((e) => m`${e}`), m`, `)}) THEN 1 ELSE 0 END)`.as("logins"),
18905
19023
  signups: m`SUM(CASE WHEN ${k.type} = 'ss' THEN 1 ELSE 0 END)`.as("signups"),
18906
- leaked_passwords: m`SUM(CASE WHEN ${k.type} IN (${m.join(DS.map((e) => m`${e}`), m`, `)}) THEN 1 ELSE 0 END)`.as("leaked_passwords")
19024
+ leaked_passwords: m`SUM(CASE WHEN ${k.type} IN (${m.join(jS.map((e) => m`${e}`), m`, `)}) THEN 1 ELSE 0 END)`.as("leaked_passwords")
18907
19025
  }).from(k).where(g(h(k.tenant_id, t), Me(k.date, i), Pe(k.date, `${a}T23:59:59.999Z`))).groupBy(m`substr(${k.date}, 1, 10)`).orderBy(m`substr(${k.date}, 1, 10)`).all()).map((e) => ({
18908
19026
  date: e.date,
18909
19027
  logins: Number(e.logins) || 0,
@@ -18914,14 +19032,14 @@ function kS(e) {
18914
19032
  }));
18915
19033
  },
18916
19034
  async getActiveUsers(t) {
18917
- let n = (/* @__PURE__ */ new Date(Date.now() - 720 * 60 * 60 * 1e3)).toISOString(), [r] = await e.select({ count: m`COUNT(DISTINCT ${k.user_id})`.as("count") }).from(k).where(g(h(k.tenant_id, t), Me(k.date, n), m`${k.type} IN (${m.join(ES.map((e) => m`${e}`), m`, `)})`));
19035
+ let n = (/* @__PURE__ */ new Date(Date.now() - 720 * 60 * 60 * 1e3)).toISOString(), [r] = await e.select({ count: m`COUNT(DISTINCT ${k.user_id})`.as("count") }).from(k).where(g(h(k.tenant_id, t), Me(k.date, n), m`${k.type} IN (${m.join(AS.map((e) => m`${e}`), m`, `)})`));
18918
19036
  return Number(r?.count) || 0;
18919
19037
  }
18920
19038
  };
18921
19039
  }
18922
19040
  //#endregion
18923
19041
  //#region src/adapters/analytics.ts
18924
- var AS = {
19042
+ var PS = {
18925
19043
  "active-users": ["s", "seacft"],
18926
19044
  logins: [
18927
19045
  "s",
@@ -18951,7 +19069,7 @@ var AS = {
18951
19069
  "fvr"
18952
19070
  ],
18953
19071
  "codes-sent": ["cls", "cs"]
18954
- }, jS = {
19072
+ }, FS = {
18955
19073
  "active-users": {
18956
19074
  alias: "active_users",
18957
19075
  type: "UInt64",
@@ -19008,7 +19126,7 @@ var AS = {
19008
19126
  agg: "count"
19009
19127
  }
19010
19128
  };
19011
- function MS(e) {
19129
+ function IS(e) {
19012
19130
  switch (e) {
19013
19131
  case "hour": return m`substr(${k.date}, 1, 13)`;
19014
19132
  case "month": return m`substr(${k.date}, 1, 7)`;
@@ -19017,10 +19135,10 @@ function MS(e) {
19017
19135
  default: throw Error(`Unsupported interval '${e}' for SQL analytics adapter`);
19018
19136
  }
19019
19137
  }
19020
- function NS(e) {
19138
+ function LS(e) {
19021
19139
  return `"${e.replace(/"/g, "\"\"")}"`;
19022
19140
  }
19023
- function PS(e) {
19141
+ function RS(e) {
19024
19142
  switch (e) {
19025
19143
  case "connection": return k.connection;
19026
19144
  case "client_id": return k.client_id;
@@ -19029,9 +19147,9 @@ function PS(e) {
19029
19147
  case "time": throw Error("time dimension handled separately");
19030
19148
  }
19031
19149
  }
19032
- function FS(e) {
19150
+ function zS(e) {
19033
19151
  return { async query(t, n, r) {
19034
- let i = Date.now(), a = AS[n], o = jS[n], s = [
19152
+ let i = Date.now(), a = PS[n], o = FS[n], s = [
19035
19153
  h(k.tenant_id, t),
19036
19154
  Me(k.date, r.from),
19037
19155
  Ne(k.date, r.to),
@@ -19040,13 +19158,13 @@ function FS(e) {
19040
19158
  r.filters.connection?.length && s.push(Fe(k.connection, r.filters.connection)), r.filters.client_id?.length && s.push(Fe(k.client_id, r.filters.client_id)), r.filters.user_type?.length && s.push(Fe(k.strategy_type, r.filters.user_type)), r.filters.user_id?.length && s.push(Fe(k.user_id, r.filters.user_id));
19041
19159
  let c = {}, l = [], u = [];
19042
19160
  for (let e of r.group_by) if (e === "time") {
19043
- let e = MS(r.interval);
19161
+ let e = IS(r.interval);
19044
19162
  c.time = e, l.push(e), u.push({
19045
19163
  name: "time",
19046
19164
  type: r.interval === "hour" ? "DateTime" : "Date"
19047
19165
  });
19048
19166
  } else {
19049
- let t = PS(e);
19167
+ let t = RS(e);
19050
19168
  c[e] = t, l.push(t), u.push({
19051
19169
  name: e,
19052
19170
  type: "String"
@@ -19062,9 +19180,9 @@ function FS(e) {
19062
19180
  if (r.order_by) {
19063
19181
  let e = r.order_by.startsWith("-"), t = e ? r.order_by.slice(1) : r.order_by;
19064
19182
  if (!f.has(t)) throw Error(`Invalid order_by column '${t}' for analytics query`);
19065
- let n = NS(t);
19183
+ let n = LS(t);
19066
19184
  d = d.orderBy(m.raw(`${n} ${e ? "DESC" : "ASC"}`));
19067
- } else d = r.group_by[0] === "time" ? d.orderBy(m.raw(`${NS("time")} ASC`)) : d.orderBy(m.raw(`${NS(o.alias)} DESC`));
19185
+ } else d = r.group_by[0] === "time" ? d.orderBy(m.raw(`${LS("time")} ASC`)) : d.orderBy(m.raw(`${LS(o.alias)} DESC`));
19068
19186
  d = d.limit(r.limit).offset(r.offset);
19069
19187
  let p = (await d.all()).map((e) => {
19070
19188
  let t = {};
@@ -19084,117 +19202,11 @@ function FS(e) {
19084
19202
  } };
19085
19203
  }
19086
19204
  //#endregion
19087
- //#region src/adapters/outbox.ts
19088
- Je();
19089
- function IS(e) {
19090
- return {
19091
- ...e,
19092
- payload: N(e.payload, {})
19093
- };
19094
- }
19095
- function LS(e) {
19096
- return {
19097
- async create(t, n) {
19098
- let r = qe(), i = (/* @__PURE__ */ new Date()).toISOString();
19099
- return await e.insert(A).values({
19100
- id: r,
19101
- tenant_id: t,
19102
- event_type: n.event_type,
19103
- log_type: n.log_type,
19104
- aggregate_type: n.aggregate_type,
19105
- aggregate_id: n.aggregate_id,
19106
- payload: JSON.stringify({
19107
- ...n,
19108
- id: r
19109
- }),
19110
- created_at: i,
19111
- processed_at: null,
19112
- retry_count: 0,
19113
- next_retry_at: null,
19114
- error: null,
19115
- claimed_by: null,
19116
- claim_expires_at: null
19117
- }), r;
19118
- },
19119
- async getByIds(t) {
19120
- return t.length === 0 ? [] : (await e.select().from(A).where(Fe(A.id, t)).all()).map(IS);
19121
- },
19122
- async getUnprocessed(t) {
19123
- let n = (/* @__PURE__ */ new Date()).toISOString();
19124
- return (await e.select().from(A).where(g(Ie(A.processed_at), Ae(Ie(A.next_retry_at), Pe(A.next_retry_at, n)), Ae(Ie(A.claimed_by), Pe(A.claim_expires_at, n)))).orderBy(A.created_at, A.id).limit(t).all()).map(IS);
19125
- },
19126
- async claimEvents(t, n, r) {
19127
- if (t.length === 0) return [];
19128
- let i = (/* @__PURE__ */ new Date()).toISOString(), a = new Date(Date.now() + r).toISOString();
19129
- return await e.update(A).set({
19130
- claimed_by: n,
19131
- claim_expires_at: a
19132
- }).where(g(Fe(A.id, t), Ie(A.processed_at), Ae(Ie(A.claimed_by), Pe(A.claim_expires_at, i)))), (await e.select({ id: A.id }).from(A).where(g(Fe(A.id, t), h(A.claimed_by, n))).all()).map((e) => e.id);
19133
- },
19134
- async markProcessed(t) {
19135
- t.length !== 0 && await e.update(A).set({ processed_at: (/* @__PURE__ */ new Date()).toISOString() }).where(Fe(A.id, t));
19136
- },
19137
- async markRetry(t, n, r) {
19138
- await e.update(A).set({
19139
- error: n,
19140
- next_retry_at: r,
19141
- retry_count: m`${A.retry_count} + 1`,
19142
- claimed_by: null,
19143
- claim_expires_at: null
19144
- }).where(h(A.id, t));
19145
- },
19146
- async cleanup(t) {
19147
- return (await e.delete(A).where(g(m`${A.processed_at} IS NOT NULL`, Pe(A.processed_at, t))).returning()).length;
19148
- },
19149
- async deadLetter(t, n) {
19150
- let r = (/* @__PURE__ */ new Date()).toISOString();
19151
- await e.update(A).set({
19152
- processed_at: r,
19153
- dead_lettered_at: r,
19154
- final_error: n
19155
- }).where(h(A.id, t));
19156
- },
19157
- async listFailed(t, n = {}) {
19158
- let { page: r = 0, per_page: i = 50, include_totals: a = !1 } = n, o = (await e.select().from(A).where(g(h(A.tenant_id, t), Le(A.dead_lettered_at))).orderBy(v(A.dead_lettered_at), _(A.id)).offset(r * i).limit(i).all()).map((e) => ({
19159
- ...N(e.payload, {}),
19160
- id: e.id,
19161
- created_at: e.created_at,
19162
- processed_at: e.processed_at,
19163
- retry_count: e.retry_count,
19164
- next_retry_at: e.next_retry_at,
19165
- error: e.error,
19166
- dead_lettered_at: e.dead_lettered_at,
19167
- final_error: e.final_error
19168
- })), s = o.length;
19169
- if (a) {
19170
- let [n] = await e.select({ total: Be() }).from(A).where(g(h(A.tenant_id, t), Le(A.dead_lettered_at)));
19171
- s = Number(n?.total ?? o.length);
19172
- }
19173
- return {
19174
- events: o,
19175
- start: r * i,
19176
- limit: i,
19177
- length: s
19178
- };
19179
- },
19180
- async replay(t, n) {
19181
- return (await e.update(A).set({
19182
- processed_at: null,
19183
- dead_lettered_at: null,
19184
- final_error: null,
19185
- retry_count: 0,
19186
- next_retry_at: null,
19187
- error: null
19188
- }).where(g(h(A.id, t), h(A.tenant_id, n), Le(A.dead_lettered_at))).returning()).length > 0;
19189
- }
19190
- };
19191
- }
19192
- //#endregion
19193
19205
  //#region src/adapters/cleanup.ts
19194
- var RS = 10080 * 60 * 1e3;
19195
- function zS(e) {
19206
+ var BS = 10080 * 60 * 1e3;
19207
+ function VS(e) {
19196
19208
  return async (t) => {
19197
- let n = Date.now() - RS;
19209
+ let n = Date.now() - BS;
19198
19210
  try {
19199
19211
  let r = [Ae(Ne(T.expires_at_ts, n), Ne(T.idle_expires_at_ts, n))];
19200
19212
  t?.tenant_id && r.push(h(T.tenant_id, t.tenant_id)), await e.delete(T).where(g(...r)), r = [Ae(Ne(Yt.expires_at_ts, n), Ne(Yt.idle_expires_at_ts, n))], t?.tenant_id && r.push(h(Yt.tenant_id, t.tenant_id)), t?.user_id && r.push(h(Yt.user_id, t.user_id)), await e.delete(Yt).where(g(...r)), r = [Ne(E.expires_at_ts, n)], t?.tenant_id && r.push(h(E.tenant_id, t.tenant_id)), await e.delete(E).where(g(...r));
@@ -19205,7 +19217,7 @@ function zS(e) {
19205
19217
  }
19206
19218
  //#endregion
19207
19219
  //#region src/schema/control-plane/tenantOperations.ts
19208
- var BS = x("tenant_operations", {
19220
+ var HS = x("tenant_operations", {
19209
19221
  id: b("id", { length: 255 }).primaryKey(),
19210
19222
  tenant_id: b("tenant_id", { length: 255 }),
19211
19223
  rollout_id: b("rollout_id", { length: 255 }),
@@ -19225,7 +19237,7 @@ var BS = x("tenant_operations", {
19225
19237
  S("tenant_operations_tenant_id_created_at_idx").on(e.tenant_id, e.created_at),
19226
19238
  S("tenant_operations_rollout_id_idx").on(e.rollout_id),
19227
19239
  S("tenant_operations_status_idx").on(e.status)
19228
- ]), VS = x("tenant_operation_events", {
19240
+ ]), US = x("tenant_operation_events", {
19229
19241
  id: b("id", { length: 255 }).primaryKey(),
19230
19242
  operation_id: b("operation_id", { length: 255 }).notNull(),
19231
19243
  step: b("step", { length: 255 }).notNull(),
@@ -19235,9 +19247,9 @@ var BS = x("tenant_operations", {
19235
19247
  created_at: b("created_at", { length: 35 }).notNull()
19236
19248
  }, (e) => [Ze({
19237
19249
  columns: [e.operation_id],
19238
- foreignColumns: [BS.id],
19250
+ foreignColumns: [HS.id],
19239
19251
  name: "tenant_operation_events_operation_id_constraint"
19240
- }).onDelete("cascade"), S("tenant_operation_events_operation_id_created_at_idx").on(e.operation_id, e.created_at)]), HS = x("rollouts", {
19252
+ }).onDelete("cascade"), S("tenant_operation_events_operation_id_created_at_idx").on(e.operation_id, e.created_at)]), WS = x("rollouts", {
19241
19253
  id: b("id", { length: 255 }).primaryKey(),
19242
19254
  kind: b("kind", { length: 32 }).notNull(),
19243
19255
  status: b("status", { length: 32 }).notNull(),
@@ -19254,7 +19266,7 @@ var BS = x("tenant_operations", {
19254
19266
  //#endregion
19255
19267
  //#region src/adapters/tenantOperations.ts
19256
19268
  Je();
19257
- function US(e) {
19269
+ function GS(e) {
19258
19270
  return Yy.parse({
19259
19271
  id: e.id,
19260
19272
  tenant_id: e.tenant_id,
@@ -19273,7 +19285,7 @@ function US(e) {
19273
19285
  finished_at: e.finished_at
19274
19286
  });
19275
19287
  }
19276
- function WS(e) {
19288
+ function KS(e) {
19277
19289
  return {
19278
19290
  async create(t) {
19279
19291
  let n = Jy.parse(t), r = (/* @__PURE__ */ new Date()).toISOString(), i = {
@@ -19293,63 +19305,63 @@ function WS(e) {
19293
19305
  updated_at: r,
19294
19306
  finished_at: null
19295
19307
  };
19296
- await e.insert(BS).values(i);
19308
+ await e.insert(HS).values(i);
19297
19309
  let a = await this.get(i.id);
19298
19310
  if (!a) throw Error(`Failed to create tenant operation ${i.id}`);
19299
19311
  return a;
19300
19312
  },
19301
19313
  async get(t) {
19302
- let n = await e.select().from(BS).where(h(BS.id, t)).limit(1);
19303
- return n[0] ? US(n[0]) : null;
19314
+ let n = await e.select().from(HS).where(h(HS.id, t)).limit(1);
19315
+ return n[0] ? GS(n[0]) : null;
19304
19316
  },
19305
19317
  async list(t = {}) {
19306
19318
  let n = t.page ?? 0, r = t.per_page ?? 50, i = [];
19307
- if (t.tenant_id !== void 0 && i.push(h(BS.tenant_id, t.tenant_id)), t.rollout_id !== void 0 && i.push(h(BS.rollout_id, t.rollout_id)), t.kind !== void 0 && i.push(h(BS.kind, t.kind)), t.status !== void 0) {
19319
+ if (t.tenant_id !== void 0 && i.push(h(HS.tenant_id, t.tenant_id)), t.rollout_id !== void 0 && i.push(h(HS.rollout_id, t.rollout_id)), t.kind !== void 0 && i.push(h(HS.kind, t.kind)), t.status !== void 0) {
19308
19320
  let e = Array.isArray(t.status) ? t.status : [t.status];
19309
- i.push(Fe(BS.status, e));
19321
+ i.push(Fe(HS.status, e));
19310
19322
  }
19311
- t.engine !== void 0 && i.push(h(BS.engine, t.engine)), t.updated_before !== void 0 && i.push(Ne(BS.updated_at, t.updated_before));
19312
- let a = await e.select().from(BS).where(i.length ? g(...i) : void 0).orderBy(v(BS.created_at), v(BS.id)).offset(n * r).limit(r);
19323
+ t.engine !== void 0 && i.push(h(HS.engine, t.engine)), t.updated_before !== void 0 && i.push(Ne(HS.updated_at, t.updated_before));
19324
+ let a = await e.select().from(HS).where(i.length ? g(...i) : void 0).orderBy(v(HS.created_at), v(HS.id)).offset(n * r).limit(r);
19313
19325
  return {
19314
- operations: a.map(US),
19326
+ operations: a.map(GS),
19315
19327
  start: n * r,
19316
19328
  limit: r,
19317
19329
  length: a.length
19318
19330
  };
19319
19331
  },
19320
19332
  async update(t, n) {
19321
- if ((await e.select({ id: BS.id }).from(BS).where(h(BS.id, t)).limit(1)).length === 0) return !1;
19333
+ if ((await e.select({ id: HS.id }).from(HS).where(h(HS.id, t)).limit(1)).length === 0) return !1;
19322
19334
  let r = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
19323
- return n.status !== void 0 && (r.status = n.status), n.current_step !== void 0 && (r.current_step = n.current_step), n.engine_instance_id !== void 0 && (r.engine_instance_id = n.engine_instance_id), n.target_worker_version !== void 0 && (r.target_worker_version = n.target_worker_version), n.target_database_version !== void 0 && (r.target_database_version = n.target_database_version), n.error !== void 0 && (r.error = n.error), n.finished_at !== void 0 && (r.finished_at = n.finished_at), await e.update(BS).set(r).where(h(BS.id, t)), !0;
19335
+ return n.status !== void 0 && (r.status = n.status), n.current_step !== void 0 && (r.current_step = n.current_step), n.engine_instance_id !== void 0 && (r.engine_instance_id = n.engine_instance_id), n.target_worker_version !== void 0 && (r.target_worker_version = n.target_worker_version), n.target_database_version !== void 0 && (r.target_database_version = n.target_database_version), n.error !== void 0 && (r.error = n.error), n.finished_at !== void 0 && (r.finished_at = n.finished_at), await e.update(HS).set(r).where(h(HS.id, t)), !0;
19324
19336
  },
19325
19337
  async remove(t) {
19326
- return (await e.select({ id: BS.id }).from(BS).where(h(BS.id, t)).limit(1)).length === 0 ? !1 : (await e.delete(BS).where(h(BS.id, t)), !0);
19338
+ return (await e.select({ id: HS.id }).from(HS).where(h(HS.id, t)).limit(1)).length === 0 ? !1 : (await e.delete(HS).where(h(HS.id, t)), !0);
19327
19339
  }
19328
19340
  };
19329
19341
  }
19330
19342
  //#endregion
19331
19343
  //#region src/helpers/monotonic-id.ts
19332
- var GS = "0123456789ABCDEFGHJKMNPQRSTVWXYZ", KS = 32, qS = 10, JS = 4, YS = 10;
19333
- function XS(e, t) {
19344
+ var qS = "0123456789ABCDEFGHJKMNPQRSTVWXYZ", JS = 32, YS = 10, XS = 4, ZS = 10;
19345
+ function QS(e, t) {
19334
19346
  let n = "";
19335
- for (let r = t; r > 0; r--) n = GS.charAt(e % KS) + n, e = Math.floor(e / KS);
19347
+ for (let r = t; r > 0; r--) n = qS.charAt(e % JS) + n, e = Math.floor(e / JS);
19336
19348
  return n;
19337
19349
  }
19338
- function ZS() {
19339
- let e = new Uint8Array(YS);
19350
+ function $S() {
19351
+ let e = new Uint8Array(ZS);
19340
19352
  crypto.getRandomValues(e);
19341
19353
  let t = "";
19342
- for (let n = 0; n < YS; n++) t += GS.charAt(e[n] % KS);
19354
+ for (let n = 0; n < ZS; n++) t += qS.charAt(e[n] % JS);
19343
19355
  return t;
19344
19356
  }
19345
- var QS = 0, $S = 0;
19346
- function eC() {
19357
+ var eC = 0, tC = 0;
19358
+ function nC() {
19347
19359
  let e = Date.now();
19348
- return e === QS ? $S++ : (QS = e, $S = 0), XS(e, qS) + XS($S, JS) + ZS();
19360
+ return e === eC ? tC++ : (eC = e, tC = 0), QS(e, YS) + QS(tC, XS) + $S();
19349
19361
  }
19350
19362
  //#endregion
19351
19363
  //#region src/adapters/tenantOperationEvents.ts
19352
- function tC(e) {
19364
+ function rC(e) {
19353
19365
  if (!e) return null;
19354
19366
  try {
19355
19367
  let t = JSON.parse(e);
@@ -19357,22 +19369,22 @@ function tC(e) {
19357
19369
  } catch {}
19358
19370
  return null;
19359
19371
  }
19360
- function nC(e) {
19372
+ function iC(e) {
19361
19373
  return Qy.parse({
19362
19374
  id: e.id,
19363
19375
  operation_id: e.operation_id,
19364
19376
  step: e.step,
19365
19377
  outcome: e.outcome,
19366
- detail: tC(e.detail),
19378
+ detail: rC(e.detail),
19367
19379
  attempt: e.attempt,
19368
19380
  created_at: e.created_at
19369
19381
  });
19370
19382
  }
19371
- function rC(e) {
19383
+ function aC(e) {
19372
19384
  return {
19373
19385
  async create(t) {
19374
19386
  let n = Zy.parse(t), r = {
19375
- id: `evt_${eC()}`,
19387
+ id: `evt_${nC()}`,
19376
19388
  operation_id: n.operation_id,
19377
19389
  step: n.step,
19378
19390
  outcome: n.outcome,
@@ -19380,7 +19392,7 @@ function rC(e) {
19380
19392
  attempt: n.attempt,
19381
19393
  created_at: (/* @__PURE__ */ new Date()).toISOString()
19382
19394
  };
19383
- return await e.insert(VS).values(r), Qy.parse({
19395
+ return await e.insert(US).values(r), Qy.parse({
19384
19396
  id: r.id,
19385
19397
  operation_id: r.operation_id,
19386
19398
  step: r.step,
@@ -19391,9 +19403,9 @@ function rC(e) {
19391
19403
  });
19392
19404
  },
19393
19405
  async listByOperation(t, n = {}) {
19394
- let r = n.page ?? 0, i = n.per_page ?? 100, a = await e.select().from(VS).where(h(VS.operation_id, t)).orderBy(_(VS.created_at), _(VS.id)).offset(r * i).limit(i);
19406
+ let r = n.page ?? 0, i = n.per_page ?? 100, a = await e.select().from(US).where(h(US.operation_id, t)).orderBy(_(US.created_at), _(US.id)).offset(r * i).limit(i);
19395
19407
  return {
19396
- events: a.map(nC),
19408
+ events: a.map(iC),
19397
19409
  start: r * i,
19398
19410
  limit: i,
19399
19411
  length: a.length
@@ -19404,7 +19416,7 @@ function rC(e) {
19404
19416
  //#endregion
19405
19417
  //#region src/adapters/rollouts.ts
19406
19418
  Je();
19407
- function iC(e) {
19419
+ function oC(e) {
19408
19420
  if (!e) return null;
19409
19421
  try {
19410
19422
  return JSON.parse(e);
@@ -19412,7 +19424,7 @@ function iC(e) {
19412
19424
  return null;
19413
19425
  }
19414
19426
  }
19415
- function aC(e) {
19427
+ function sC(e) {
19416
19428
  return nb.parse({
19417
19429
  id: e.id,
19418
19430
  kind: e.kind,
@@ -19420,15 +19432,15 @@ function aC(e) {
19420
19432
  target_worker_version: e.target_worker_version,
19421
19433
  target_database_version: e.target_database_version,
19422
19434
  wave_size: e.wave_size,
19423
- canary_tenant_ids: iC(e.canary_tenant_ids),
19424
- filter: iC(e.filter),
19435
+ canary_tenant_ids: oC(e.canary_tenant_ids),
19436
+ filter: oC(e.filter),
19425
19437
  initiated_by: e.initiated_by,
19426
19438
  created_at: e.created_at,
19427
19439
  updated_at: e.updated_at,
19428
19440
  finished_at: e.finished_at
19429
19441
  });
19430
19442
  }
19431
- function oC(e) {
19443
+ function cC(e) {
19432
19444
  return {
19433
19445
  async create(t) {
19434
19446
  let n = tb.parse(t), r = (/* @__PURE__ */ new Date()).toISOString(), i = {
@@ -19445,37 +19457,37 @@ function oC(e) {
19445
19457
  updated_at: r,
19446
19458
  finished_at: null
19447
19459
  };
19448
- await e.insert(HS).values(i);
19460
+ await e.insert(WS).values(i);
19449
19461
  let a = await this.get(i.id);
19450
19462
  if (!a) throw Error(`Failed to create rollout ${i.id}`);
19451
19463
  return a;
19452
19464
  },
19453
19465
  async get(t) {
19454
- let n = await e.select().from(HS).where(h(HS.id, t)).limit(1);
19455
- return n[0] ? aC(n[0]) : null;
19466
+ let n = await e.select().from(WS).where(h(WS.id, t)).limit(1);
19467
+ return n[0] ? sC(n[0]) : null;
19456
19468
  },
19457
19469
  async list(t = {}) {
19458
- let n = t.page ?? 0, r = t.per_page ?? 50, i = await e.select().from(HS).orderBy(v(HS.created_at), v(HS.id)).offset(n * r).limit(r);
19470
+ let n = t.page ?? 0, r = t.per_page ?? 50, i = await e.select().from(WS).orderBy(v(WS.created_at), v(WS.id)).offset(n * r).limit(r);
19459
19471
  return {
19460
- rollouts: i.map(aC),
19472
+ rollouts: i.map(sC),
19461
19473
  start: n * r,
19462
19474
  limit: r,
19463
19475
  length: i.length
19464
19476
  };
19465
19477
  },
19466
19478
  async update(t, n) {
19467
- if ((await e.select({ id: HS.id }).from(HS).where(h(HS.id, t)).limit(1)).length === 0) return !1;
19479
+ if ((await e.select({ id: WS.id }).from(WS).where(h(WS.id, t)).limit(1)).length === 0) return !1;
19468
19480
  let r = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
19469
- return n.status !== void 0 && (r.status = n.status), n.wave_size !== void 0 && (r.wave_size = n.wave_size), n.canary_tenant_ids !== void 0 && (r.canary_tenant_ids = n.canary_tenant_ids ? JSON.stringify(n.canary_tenant_ids) : null), n.filter !== void 0 && (r.filter = n.filter ? JSON.stringify(n.filter) : null), n.finished_at !== void 0 && (r.finished_at = n.finished_at), await e.update(HS).set(r).where(h(HS.id, t)), !0;
19481
+ return n.status !== void 0 && (r.status = n.status), n.wave_size !== void 0 && (r.wave_size = n.wave_size), n.canary_tenant_ids !== void 0 && (r.canary_tenant_ids = n.canary_tenant_ids ? JSON.stringify(n.canary_tenant_ids) : null), n.filter !== void 0 && (r.filter = n.filter ? JSON.stringify(n.filter) : null), n.finished_at !== void 0 && (r.finished_at = n.finished_at), await e.update(WS).set(r).where(h(WS.id, t)), !0;
19470
19482
  },
19471
19483
  async remove(t) {
19472
- return (await e.select({ id: HS.id }).from(HS).where(h(HS.id, t)).limit(1)).length === 0 ? !1 : (await e.delete(HS).where(h(HS.id, t)), !0);
19484
+ return (await e.select({ id: WS.id }).from(WS).where(h(WS.id, t)).limit(1)).length === 0 ? !1 : (await e.delete(WS).where(h(WS.id, t)), !0);
19473
19485
  }
19474
19486
  };
19475
19487
  }
19476
19488
  //#endregion
19477
19489
  //#region src/adapters/index.ts
19478
- function sC(e, t = { useTransactions: !0 }) {
19490
+ function lC(e, t = { useTransactions: !0 }) {
19479
19491
  let n = {
19480
19492
  actions: Bn(e),
19481
19493
  actionExecutions: Vn(e),
@@ -19511,22 +19523,22 @@ function sC(e, t = { useTransactions: !0 }) {
19511
19523
  userPermissions: Jx(e),
19512
19524
  roles: Xx(e),
19513
19525
  sessions: tS(e),
19514
- sessionCleanup: zS(e),
19526
+ sessionCleanup: VS(e),
19515
19527
  tenants: oS(e),
19516
19528
  ...t.controlPlane ? {
19517
- tenantOperations: WS(e),
19518
- tenantOperationEvents: rC(e),
19519
- rollouts: oC(e)
19529
+ tenantOperations: KS(e),
19530
+ tenantOperationEvents: aC(e),
19531
+ rollouts: cC(e)
19520
19532
  } : {},
19521
19533
  themes: lS(e),
19522
19534
  universalLoginTemplates: uS(e),
19523
- users: CS(e),
19535
+ users: DS(e),
19524
19536
  userActivity: fS(e),
19525
- userRoles: wS(e),
19526
- userOrganizations: TS(e),
19527
- stats: kS(e),
19528
- analytics: FS(e),
19529
- outbox: LS(e),
19537
+ userRoles: OS(e),
19538
+ userOrganizations: kS(e),
19539
+ stats: NS(e),
19540
+ analytics: zS(e),
19541
+ outbox: hS(e),
19530
19542
  async transaction(r) {
19531
19543
  if (t.useTransactions === !1 || Hn(e)) return r(n);
19532
19544
  await e.run(m`BEGIN`);
@@ -19542,7 +19554,7 @@ function sC(e, t = { useTransactions: !0 }) {
19542
19554
  }
19543
19555
  //#endregion
19544
19556
  //#region src/adapters/resolveHost.ts
19545
- function cC(e) {
19557
+ function uC(e) {
19546
19558
  if (!e) return { path: "/*" };
19547
19559
  try {
19548
19560
  let t = JSON.parse(e), n = lb.safeParse(t);
@@ -19550,7 +19562,7 @@ function cC(e) {
19550
19562
  } catch {}
19551
19563
  return { path: "/*" };
19552
19564
  }
19553
- function lC(e) {
19565
+ function dC(e) {
19554
19566
  if (!e) return [];
19555
19567
  try {
19556
19568
  let t = JSON.parse(e);
@@ -19565,7 +19577,7 @@ function lC(e) {
19565
19577
  return [];
19566
19578
  }
19567
19579
  }
19568
- async function uC(e, t) {
19580
+ async function fC(e, t) {
19569
19581
  let n = t.toLowerCase(), r = (await e.select({
19570
19582
  custom_domain_id: rn.custom_domain_id,
19571
19583
  tenant_id: rn.tenant_id,
@@ -19577,8 +19589,8 @@ async function uC(e, t) {
19577
19589
  tenant_id: e.tenant_id,
19578
19590
  custom_domain_id: e.custom_domain_id,
19579
19591
  priority: e.priority,
19580
- match: cC(e.match),
19581
- handlers: lC(e.handlers),
19592
+ match: uC(e.match),
19593
+ handlers: dC(e.handlers),
19582
19594
  created_at: e.created_at,
19583
19595
  updated_at: e.updated_at
19584
19596
  }));
@@ -19591,11 +19603,11 @@ async function uC(e, t) {
19591
19603
  }
19592
19604
  //#endregion
19593
19605
  //#region src/adapters/proxyData.ts
19594
- function dC(e) {
19606
+ function pC(e) {
19595
19607
  return {
19596
19608
  proxyRoutes: Lx(e),
19597
- resolveHost: (t) => uC(e, t)
19609
+ resolveHost: (t) => fC(e, t)
19598
19610
  };
19599
19611
  }
19600
19612
  //#endregion
19601
- export { dC as createProxyDataAdapter, Lx as createProxyRoutesAdapter, sC as default, Dn as sqlite };
19613
+ export { pC as createProxyDataAdapter, Lx as createProxyRoutesAdapter, lC as default, Dn as sqlite };