@authhero/kysely-adapter 10.2.0 → 10.3.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.
@@ -4,7 +4,7 @@ var le = (t) => {
4
4
  };
5
5
  var Ee = (t, e, a) => e in t ? ze(t, e, { enumerable: !0, configurable: !0, writable: !0, value: a }) : t[e] = a;
6
6
  var j = (t, e, a) => Ee(t, typeof e != "symbol" ? e + "" : e, a), R = (t, e, a) => e.has(t) || le("Cannot " + a);
7
- var c = (t, e, a) => (R(t, e, "read from private field"), a ? a.call(t) : e.get(t)), y = (t, e, a) => e.has(t) ? le("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, a), M = (t, e, a, r) => (R(t, e, "write to private field"), r ? r.call(t, a) : e.set(t, a), a), u = (t, e, a) => (R(t, e, "access private method"), a);
7
+ var d = (t, e, a) => (R(t, e, "read from private field"), a ? a.call(t) : e.get(t)), y = (t, e, a) => e.has(t) ? le("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, a), M = (t, e, a, r) => (R(t, e, "write to private field"), r ? r.call(t, a) : e.set(t, a), a), u = (t, e, a) => (R(t, e, "access private method"), a);
8
8
  import { parseUserId as Y, codeSchema as Je, connectionSchema as Ke, loginSessionSchema as Re, promptSettingSchema as Ue } from "@authhero/adapter-interfaces";
9
9
  import "@hono/zod-openapi";
10
10
  var V = class extends Error {
@@ -25,8 +25,8 @@ var V = class extends Error {
25
25
  };
26
26
  function Be(t) {
27
27
  return async (e, a) => {
28
- const { identities: r, ...n } = a, o = {
29
- ...n,
28
+ const { identities: r, ...o } = a, n = {
29
+ ...o,
30
30
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
31
31
  updated_at: (/* @__PURE__ */ new Date()).toISOString(),
32
32
  login_count: 0,
@@ -37,16 +37,16 @@ function Be(t) {
37
37
  user_metadata: JSON.stringify(a.user_metadata)
38
38
  };
39
39
  try {
40
- await t.insertInto("users").values(o).execute();
40
+ await t.insertInto("users").values(n).execute();
41
41
  } catch (s) {
42
42
  throw s.code === "SQLITE_CONSTRAINT_UNIQUE" || s.message.includes("AlreadyExists") ? new V(409, { message: "User already exists" }) : new V(500, { message: `${s.code}, ${s.message}` });
43
43
  }
44
44
  return {
45
- ...o,
45
+ ...n,
46
46
  // TODO: check if this is correct. Should it be optional?
47
- email: o.email || "",
48
- email_verified: o.email_verified === 1,
49
- is_social: o.is_social === 1
47
+ email: n.email || "",
48
+ email_verified: n.email_verified === 1,
49
+ is_social: n.is_social === 1
50
50
  };
51
51
  };
52
52
  }
@@ -77,13 +77,13 @@ function fe(t) {
77
77
  }
78
78
  function Qe(t) {
79
79
  return async (e, a) => {
80
- const [r, n] = await Promise.all([
80
+ const [r, o] = await Promise.all([
81
81
  t.selectFrom("users").where("users.tenant_id", "=", e).where("users.user_id", "=", a).selectAll().executeTakeFirst(),
82
82
  t.selectFrom("users").where("users.tenant_id", "=", e).where("users.linked_to", "=", a).selectAll().execute()
83
83
  ]);
84
84
  if (!r)
85
85
  return null;
86
- const { tenant_id: o, ...s } = r, l = {
86
+ const { tenant_id: n, ...s } = r, l = {
87
87
  ...s,
88
88
  email: r.email || "",
89
89
  email_verified: r.email_verified === 1,
@@ -97,39 +97,39 @@ function Qe(t) {
97
97
  user_id: Y(r.user_id).id,
98
98
  isSocial: !!r.is_social
99
99
  },
100
- ...n.map(fe)
100
+ ...o.map(fe)
101
101
  ]
102
102
  };
103
103
  return _(l);
104
104
  };
105
105
  }
106
106
  function O(t, e, a, r) {
107
- return a.split(/\s+/).map((o) => o.replace(/^([^:]+)=/g, "$1:")).map((o) => {
108
- let s = o.startsWith("-"), l, d, g, m;
109
- return o.startsWith("-_exists_:") ? (l = o.substring(10), g = !0, s = !0) : o.startsWith("_exists_:") ? (l = o.substring(9), g = !0, s = !1) : o.includes(":") ? (s = o.startsWith("-"), [l, d] = s ? o.substring(1).split(":") : o.split(":"), g = !1, d.startsWith(">=") ? (m = ">=", d = d.substring(2)) : d.startsWith(">") ? (m = ">", d = d.substring(1)) : d.startsWith("<=") ? (m = "<=", d = d.substring(2)) : d.startsWith("<") ? (m = "<", d = d.substring(1)) : m = "=") : (l = null, d = o, g = !1), { key: l, value: d, isNegation: s, isExistsQuery: g, operator: m };
110
- }).forEach(({ key: o, value: s, isNegation: l, isExistsQuery: d, operator: g }) => {
111
- if (o)
112
- if (d)
113
- l ? e = e.where(o, "is", null) : e = e.where(o, "is not", null);
107
+ return a.split(/\s+/).map((n) => n.replace(/^([^:]+)=/g, "$1:")).map((n) => {
108
+ let s = n.startsWith("-"), l, c, g, m;
109
+ return n.startsWith("-_exists_:") ? (l = n.substring(10), g = !0, s = !0) : n.startsWith("_exists_:") ? (l = n.substring(9), g = !0, s = !1) : n.includes(":") ? (s = n.startsWith("-"), [l, c] = s ? n.substring(1).split(":") : n.split(":"), g = !1, c.startsWith(">=") ? (m = ">=", c = c.substring(2)) : c.startsWith(">") ? (m = ">", c = c.substring(1)) : c.startsWith("<=") ? (m = "<=", c = c.substring(2)) : c.startsWith("<") ? (m = "<", c = c.substring(1)) : m = "=") : (l = null, c = n, g = !1), { key: l, value: c, isNegation: s, isExistsQuery: g, operator: m };
110
+ }).forEach(({ key: n, value: s, isNegation: l, isExistsQuery: c, operator: g }) => {
111
+ if (n)
112
+ if (c)
113
+ l ? e = e.where(n, "is", null) : e = e.where(n, "is not", null);
114
114
  else if (l)
115
115
  switch (g) {
116
116
  case ">":
117
- e = e.where(o, "<=", s);
117
+ e = e.where(n, "<=", s);
118
118
  break;
119
119
  case ">=":
120
- e = e.where(o, "<", s);
120
+ e = e.where(n, "<", s);
121
121
  break;
122
122
  case "<":
123
- e = e.where(o, ">=", s);
123
+ e = e.where(n, ">=", s);
124
124
  break;
125
125
  case "<=":
126
- e = e.where(o, ">", s);
126
+ e = e.where(n, ">", s);
127
127
  break;
128
128
  default:
129
- e = e.where(o, "!=", s);
129
+ e = e.where(n, "!=", s);
130
130
  }
131
131
  else
132
- e = e.where(o, g, s);
132
+ e = e.where(n, g, s);
133
133
  else {
134
134
  const { ref: m } = t.dynamic;
135
135
  e = e.where(
@@ -154,7 +154,7 @@ function Ve(t) {
154
154
  const { ref: m } = t.dynamic;
155
155
  r = r.orderBy(m(a.sort.sort_by), a.sort.sort_order);
156
156
  }
157
- const o = await r.offset(a.page * a.per_page).limit(a.per_page).selectAll().execute(), s = o.map((m) => m.user_id), l = s.length ? await t.selectFrom("users").selectAll().where("users.tenant_id", "=", e).where("users.linked_to", "in", s).execute() : [], d = o.map((m) => {
157
+ const n = await r.offset(a.page * a.per_page).limit(a.per_page).selectAll().execute(), s = n.map((m) => m.user_id), l = s.length ? await t.selectFrom("users").selectAll().where("users.tenant_id", "=", e).where("users.linked_to", "in", s).execute() : [], c = n.map((m) => {
158
158
  const w = l.filter(
159
159
  (b) => b.linked_to === m.user_id
160
160
  );
@@ -176,7 +176,7 @@ function Ve(t) {
176
176
  });
177
177
  }), { count: g } = await r.select((m) => m.fn.countAll().as("count")).executeTakeFirstOrThrow();
178
178
  return {
179
- users: d,
179
+ users: c,
180
180
  start: a.page * a.per_page,
181
181
  limit: a.per_page,
182
182
  length: x(g)
@@ -192,18 +192,18 @@ function qe(t) {
192
192
  }
193
193
  function Ge(t) {
194
194
  return async (e, a, r) => {
195
- const n = {
195
+ const o = {
196
196
  ...r,
197
197
  email_verified: qe(r),
198
198
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
199
199
  };
200
- return r.app_metadata && (n.app_metadata = JSON.stringify(r.app_metadata)), r.user_metadata && (n.user_metadata = JSON.stringify(r.user_metadata)), (await t.updateTable("users").set(n).where("users.tenant_id", "=", e).where("users.user_id", "=", a).execute()).length === 1;
200
+ return r.app_metadata && (o.app_metadata = JSON.stringify(r.app_metadata)), r.user_metadata && (o.user_metadata = JSON.stringify(r.user_metadata)), (await t.updateTable("users").set(o).where("users.tenant_id", "=", e).where("users.user_id", "=", a).execute()).length === 1;
201
201
  };
202
202
  }
203
203
  function He(t) {
204
- return async (e, a, r, n) => {
205
- const o = { linked_to: null };
206
- return (await t.updateTable("users").set(o).where("users.tenant_id", "=", e).where("users.user_id", "=", `${r}|${n}`).where("users.linked_to", "=", `${a}`).execute()).length === 1;
204
+ return async (e, a, r, o) => {
205
+ const n = { linked_to: null };
206
+ return (await t.updateTable("users").set(n).where("users.tenant_id", "=", e).where("users.user_id", "=", `${r}|${o}`).where("users.linked_to", "=", `${a}`).execute()).length === 1;
207
207
  };
208
208
  }
209
209
  function Xe(t) {
@@ -253,14 +253,14 @@ function tt(t) {
253
253
  a = a.orderBy(l(e.sort.sort_by), e.sort.sort_order);
254
254
  }
255
255
  e.q && (a = a.where((l) => l.or([l("name", "like", `%${e.q}%`)])));
256
- const n = await a.offset(e.page * e.per_page).limit(e.per_page).selectAll().execute();
256
+ const o = await a.offset(e.page * e.per_page).limit(e.per_page).selectAll().execute();
257
257
  if (!e.include_totals)
258
258
  return {
259
- tenants: n
259
+ tenants: o
260
260
  };
261
- const { count: o } = await a.select((l) => l.fn.countAll().as("count")).executeTakeFirstOrThrow(), s = x(o);
261
+ const { count: n } = await a.select((l) => l.fn.countAll().as("count")).executeTakeFirstOrThrow(), s = x(n);
262
262
  return {
263
- tenants: n.map(_),
263
+ tenants: o.map(_),
264
264
  start: (e.page - 1) * e.per_page,
265
265
  limit: e.per_page,
266
266
  length: s
@@ -295,7 +295,7 @@ function ue(t) {
295
295
  const ot = 1024;
296
296
  function st(t) {
297
297
  return async (e, a) => {
298
- var n, o, s;
298
+ var o, n, s;
299
299
  const r = {
300
300
  id: k(),
301
301
  ...a,
@@ -304,10 +304,10 @@ function st(t) {
304
304
  return await t.insertInto("logs").values({
305
305
  ...r,
306
306
  // Truncate long strings to avoid database errors
307
- description: (n = r.description) == null ? void 0 : n.substring(0, 256),
307
+ description: (o = r.description) == null ? void 0 : o.substring(0, 256),
308
308
  isMobile: a.isMobile ? 1 : 0,
309
309
  tenant_id: e,
310
- scope: (o = a.scope) == null ? void 0 : o.join(","),
310
+ scope: (n = a.scope) == null ? void 0 : n.join(","),
311
311
  auth0_client: ue(a.auth0_client),
312
312
  details: (s = ue(a.details)) == null ? void 0 : s.substring(0, 8192)
313
313
  }).execute(), r;
@@ -343,35 +343,35 @@ function it(t) {
343
343
  }) => {
344
344
  let r = t.selectFrom("logs").where("logs.tenant_id", "=", e);
345
345
  a.q && (r = O(t, r, a.q, ["user_id", "ip"]));
346
- let n = r;
346
+ let o = r;
347
347
  if (a.sort && a.sort.sort_by) {
348
348
  const { ref: l } = t.dynamic;
349
- n = n.orderBy(
349
+ o = o.orderBy(
350
350
  l(a.sort.sort_by),
351
351
  a.sort.sort_order
352
352
  );
353
353
  }
354
- n = n.offset(a.page * a.per_page).limit(a.per_page);
355
- const o = await n.selectAll().execute(), { count: s } = await r.select((l) => l.fn.countAll().as("count")).executeTakeFirstOrThrow();
354
+ o = o.offset(a.page * a.per_page).limit(a.per_page);
355
+ const n = await o.selectAll().execute(), { count: s } = await r.select((l) => l.fn.countAll().as("count")).executeTakeFirstOrThrow();
356
356
  return {
357
- logs: o.map(pe),
357
+ logs: n.map(pe),
358
358
  start: a.page * a.per_page,
359
359
  limit: a.per_page,
360
360
  length: x(s)
361
361
  };
362
362
  };
363
363
  }
364
- function dt(t) {
364
+ function ct(t) {
365
365
  return async (e, a) => {
366
366
  const r = await t.selectFrom("logs").where("logs.tenant_id", "=", e).where("logs.id", "=", a).selectAll().executeTakeFirst();
367
367
  return r ? pe(r) : null;
368
368
  };
369
369
  }
370
- function ct(t) {
370
+ function dt(t) {
371
371
  return {
372
372
  create: st(t),
373
373
  list: it(t),
374
- get: dt(t)
374
+ get: ct(t)
375
375
  };
376
376
  }
377
377
  function lt(t) {
@@ -379,10 +379,10 @@ function lt(t) {
379
379
  const r = await t.selectFrom("sessions").where("sessions.tenant_id", "=", e).where("sessions.id", "=", a).selectAll().executeTakeFirst();
380
380
  if (!r)
381
381
  return null;
382
- const { tenant_id: n, device: o, clients: s, ...l } = r;
382
+ const { tenant_id: o, device: n, clients: s, ...l } = r;
383
383
  return {
384
384
  ...l,
385
- device: JSON.parse(o),
385
+ device: JSON.parse(n),
386
386
  clients: JSON.parse(s)
387
387
  };
388
388
  };
@@ -409,13 +409,13 @@ function mt(t) {
409
409
  }
410
410
  function ht(t) {
411
411
  return async (e, a, r) => {
412
- const n = {
412
+ const o = {
413
413
  ...r,
414
414
  updated_at: (/* @__PURE__ */ new Date()).toISOString(),
415
415
  device: r.device ? JSON.stringify(r.device) : void 0,
416
416
  clients: r.clients ? JSON.stringify(r.clients) : void 0
417
417
  };
418
- return !!(await t.updateTable("sessions").set(n).where("tenant_id", "=", e).where("sessions.id", "=", a).execute()).length;
418
+ return !!(await t.updateTable("sessions").set(o).where("tenant_id", "=", e).where("sessions.id", "=", a).execute()).length;
419
419
  };
420
420
  }
421
421
  function _t(t) {
@@ -426,21 +426,21 @@ function _t(t) {
426
426
  }) => {
427
427
  let r = t.selectFrom("sessions").where("sessions.tenant_id", "=", e);
428
428
  a.q && (r = O(t, r, a.q, ["user_id", "session_id"]));
429
- let n = r;
429
+ let o = r;
430
430
  if (a.sort && a.sort.sort_by) {
431
- const { ref: d } = t.dynamic;
432
- n = n.orderBy(
433
- d(a.sort.sort_by),
431
+ const { ref: c } = t.dynamic;
432
+ o = o.orderBy(
433
+ c(a.sort.sort_by),
434
434
  a.sort.sort_order
435
435
  );
436
436
  }
437
- n = n.offset(a.page * a.per_page).limit(a.per_page);
438
- const o = await n.selectAll().execute(), { count: s } = await r.select((d) => d.fn.countAll().as("count")).executeTakeFirstOrThrow(), l = x(s);
437
+ o = o.offset(a.page * a.per_page).limit(a.per_page);
438
+ const n = await o.selectAll().execute(), { count: s } = await r.select((c) => c.fn.countAll().as("count")).executeTakeFirstOrThrow(), l = x(s);
439
439
  return {
440
- sessions: o.map((d) => ({
441
- ...d,
442
- device: JSON.parse(d.device),
443
- clients: JSON.parse(d.clients)
440
+ sessions: n.map((c) => ({
441
+ ...c,
442
+ device: JSON.parse(c.device),
443
+ clients: JSON.parse(c.clients)
444
444
  })),
445
445
  start: a.page * a.per_page,
446
446
  limit: a.per_page,
@@ -462,8 +462,8 @@ function pt(t) {
462
462
  const r = await t.selectFrom("passwords").where("passwords.tenant_id", "=", e).where("passwords.user_id", "=", a).selectAll().executeTakeFirst();
463
463
  if (!r)
464
464
  return null;
465
- const { tenant_id: n, ...o } = r;
466
- return o;
465
+ const { tenant_id: o, ...n } = r;
466
+ return n;
467
467
  };
468
468
  }
469
469
  function gt(t) {
@@ -500,10 +500,10 @@ function vt(t) {
500
500
  }) => {
501
501
  let r = t.selectFrom("codes").where("codes.tenant_id", "=", e);
502
502
  a.q && (r = O(t, r, a.q, ["code", "login_id"]));
503
- const o = await r.offset(a.page * a.per_page).limit(a.per_page).selectAll().execute(), { count: s } = await r.select((d) => d.fn.countAll().as("count")).executeTakeFirstOrThrow();
503
+ const n = await r.offset(a.page * a.per_page).limit(a.per_page).selectAll().execute(), { count: s } = await r.select((c) => c.fn.countAll().as("count")).executeTakeFirstOrThrow();
504
504
  return {
505
- codes: o.map((d) => {
506
- const { tenant_id: g, ...m } = d;
505
+ codes: n.map((c) => {
506
+ const { tenant_id: g, ...m } = c;
507
507
  return Je.parse(_(m));
508
508
  }),
509
509
  start: a.page * a.per_page,
@@ -529,10 +529,10 @@ function Ct(t) {
529
529
  }
530
530
  function bt(t) {
531
531
  return async (e, a, r) => {
532
- let n = t.selectFrom("codes").where("codes.code_id", "=", a).where("codes.code_type", "=", r);
533
- e.length && (n = n.where("codes.tenant_id", "=", e));
534
- const o = await n.selectAll().executeTakeFirst();
535
- return o ? _(o) : null;
532
+ let o = t.selectFrom("codes").where("codes.code_id", "=", a).where("codes.code_type", "=", r);
533
+ e.length && (o = o.where("codes.tenant_id", "=", e));
534
+ const n = await o.selectAll().executeTakeFirst();
535
+ return n ? _(n) : null;
536
536
  };
537
537
  }
538
538
  function xt(t) {
@@ -553,31 +553,31 @@ function St(t) {
553
553
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
554
554
  updated_at: (/* @__PURE__ */ new Date()).toISOString(),
555
555
  ...a
556
- }, n = JSON.stringify(a.allowed_origins), o = JSON.stringify(a.callbacks), s = JSON.stringify(a.web_origins), l = JSON.stringify(a.allowed_logout_urls), d = JSON.stringify(a.allowed_clients);
556
+ }, o = JSON.stringify(a.allowed_origins), n = JSON.stringify(a.callbacks), s = JSON.stringify(a.web_origins), l = JSON.stringify(a.allowed_logout_urls), c = JSON.stringify(a.allowed_clients);
557
557
  return await t.insertInto("applications").values({
558
558
  ...r,
559
559
  tenant_id: e,
560
560
  disable_sign_ups: a.disable_sign_ups ? 1 : 0,
561
561
  addons: a.addons ? JSON.stringify(a.addons) : "{}",
562
- callbacks: o,
563
- allowed_origins: n,
562
+ callbacks: n,
563
+ allowed_origins: o,
564
564
  web_origins: s,
565
565
  allowed_logout_urls: l,
566
- allowed_clients: d
566
+ allowed_clients: c
567
567
  }).execute(), r;
568
568
  };
569
569
  }
570
570
  function Ot(t) {
571
571
  return async (e) => ({
572
- applications: (await t.selectFrom("applications").where("applications.tenant_id", "=", e).selectAll().execute()).map((o) => ({
573
- ...o,
574
- disable_sign_ups: !!o.disable_sign_ups,
575
- addons: o.addons ? JSON.parse(o.addons) : {},
576
- callbacks: o.callbacks ? JSON.parse(o.callbacks) : [],
577
- allowed_origins: o.allowed_origins ? JSON.parse(o.allowed_origins) : [],
578
- web_origins: o.web_origins ? JSON.parse(o.web_origins) : [],
579
- allowed_logout_urls: o.allowed_logout_urls ? JSON.parse(o.allowed_logout_urls) : [],
580
- allowed_clients: o.allowed_logout_urls ? JSON.parse(o.allowed_logout_urls) : []
572
+ applications: (await t.selectFrom("applications").where("applications.tenant_id", "=", e).selectAll().execute()).map((n) => ({
573
+ ...n,
574
+ disable_sign_ups: !!n.disable_sign_ups,
575
+ addons: n.addons ? JSON.parse(n.addons) : {},
576
+ callbacks: n.callbacks ? JSON.parse(n.callbacks) : [],
577
+ allowed_origins: n.allowed_origins ? JSON.parse(n.allowed_origins) : [],
578
+ web_origins: n.web_origins ? JSON.parse(n.web_origins) : [],
579
+ allowed_logout_urls: n.allowed_logout_urls ? JSON.parse(n.allowed_logout_urls) : [],
580
+ allowed_clients: n.allowed_logout_urls ? JSON.parse(n.allowed_logout_urls) : []
581
581
  }))
582
582
  });
583
583
  }
@@ -600,7 +600,7 @@ function $t(t) {
600
600
  }
601
601
  function Dt(t) {
602
602
  return async (e, a, r) => {
603
- const n = {
603
+ const o = {
604
604
  ...r,
605
605
  updated_at: (/* @__PURE__ */ new Date()).toISOString(),
606
606
  allowed_origins: r.allowed_origins ? JSON.stringify(r.allowed_origins) : void 0,
@@ -611,7 +611,7 @@ function Dt(t) {
611
611
  addons: r.addons ? JSON.stringify(r.addons) : "{}",
612
612
  disable_sign_ups: r.disable_sign_ups ? 1 : 0
613
613
  };
614
- return await t.updateTable("applications").set(n).where("applications.id", "=", a).where("applications.tenant_id", "=", e).execute(), !0;
614
+ return await t.updateTable("applications").set(o).where("applications.id", "=", a).where("applications.tenant_id", "=", e).execute(), !0;
615
615
  };
616
616
  }
617
617
  function It(t) {
@@ -648,11 +648,11 @@ function jt(t) {
648
648
  let r = t.selectFrom("connections").where("connections.tenant_id", "=", e);
649
649
  a.q && (r = O(t, r, a.q, ["user_id", "ip"]));
650
650
  const s = (await r.offset(a.page * a.per_page).limit(a.per_page).selectAll().execute()).map(
651
- (d) => _({
652
- ...d,
653
- options: JSON.parse(d.options)
651
+ (c) => _({
652
+ ...c,
653
+ options: JSON.parse(c.options)
654
654
  })
655
- ), { count: l } = await r.select((d) => d.fn.countAll().as("count")).executeTakeFirstOrThrow();
655
+ ), { count: l } = await r.select((c) => c.fn.countAll().as("count")).executeTakeFirstOrThrow();
656
656
  return {
657
657
  connections: s,
658
658
  start: a.page * a.per_page,
@@ -675,13 +675,13 @@ function Ft(t) {
675
675
  }
676
676
  function At(t) {
677
677
  return async (e, a, r) => {
678
- const n = {
678
+ const o = {
679
679
  ...r,
680
680
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
681
681
  };
682
682
  return await t.updateTable("connections").set({
683
- ...n,
684
- options: n.options ? JSON.stringify(n.options) : void 0
683
+ ...o,
684
+ options: o.options ? JSON.stringify(o.options) : void 0
685
685
  }).where("connections.id", "=", a).where("connections.tenant_id", "=", e).execute(), !0;
686
686
  };
687
687
  }
@@ -703,10 +703,10 @@ function zt(t) {
703
703
  const r = await t.selectFrom("tenants").selectAll().where("id", "=", a.tenant_id).executeTakeFirst();
704
704
  if (!r)
705
705
  throw new V(404, { message: "Tenant not found" });
706
- const n = await t.selectFrom("connections").where("tenant_id", "=", a.tenant_id).selectAll().execute();
706
+ const o = await t.selectFrom("connections").where("tenant_id", "=", a.tenant_id).selectAll().execute();
707
707
  return {
708
708
  ...a,
709
- connections: n.map(
709
+ connections: o.map(
710
710
  (s) => Ke.parse(
711
711
  _({
712
712
  ...s,
@@ -787,12 +787,12 @@ function Vt(t) {
787
787
  }
788
788
  function Wt(t) {
789
789
  return async (e, a, r) => {
790
- const n = {
790
+ const o = {
791
791
  ...r,
792
792
  updated_at: (/* @__PURE__ */ new Date()).toISOString(),
793
793
  primary: r.primary ? 1 : 0
794
794
  };
795
- return (await t.updateTable("custom_domains").set(n).where("custom_domains.tenant_id", "=", e).where("custom_domains.custom_domain_id", "=", a).execute()).length > 0;
795
+ return (await t.updateTable("custom_domains").set(o).where("custom_domains.tenant_id", "=", e).where("custom_domains.custom_domain_id", "=", a).execute()).length > 0;
796
796
  };
797
797
  }
798
798
  function qt(t) {
@@ -811,23 +811,23 @@ function Gt(t) {
811
811
  return null;
812
812
  const {
813
813
  tenant_id: r,
814
- colors_primary: n,
815
- colors_page_background_type: o,
814
+ colors_primary: o,
815
+ colors_page_background_type: n,
816
816
  colors_page_background_start: s,
817
817
  colors_page_background_end: l,
818
- colors_page_background_angle_dev: d,
818
+ colors_page_background_angle_dev: c,
819
819
  font_url: g,
820
820
  ...m
821
821
  } = a;
822
822
  return _({
823
823
  ...m,
824
824
  colors: {
825
- primary: n,
825
+ primary: o,
826
826
  page_background: {
827
- type: o,
827
+ type: n,
828
828
  start: s,
829
829
  end: l,
830
- angle_deg: d
830
+ angle_deg: c
831
831
  }
832
832
  },
833
833
  font: g ? { url: g } : void 0
@@ -836,14 +836,14 @@ function Gt(t) {
836
836
  }
837
837
  function Ht(t) {
838
838
  return async (e, a) => {
839
- var s, l, d, g, m, w, b, Z, ee, te, ae, re, ne, oe, se, ie, de, ce;
840
- const { colors: r, font: n, ...o } = a;
839
+ var s, l, c, g, m, w, b, Z, ee, te, ae, re, ne, oe, se, ie, ce, de;
840
+ const { colors: r, font: o, ...n } = a;
841
841
  try {
842
842
  await t.insertInto("branding").values({
843
- ...o,
843
+ ...n,
844
844
  colors_primary: r == null ? void 0 : r.primary,
845
845
  colors_page_background_type: (l = (s = a.colors) == null ? void 0 : s.page_background) == null ? void 0 : l.type,
846
- colors_page_background_start: (g = (d = a.colors) == null ? void 0 : d.page_background) == null ? void 0 : g.start,
846
+ colors_page_background_start: (g = (c = a.colors) == null ? void 0 : c.page_background) == null ? void 0 : g.start,
847
847
  colors_page_background_end: (w = (m = a.colors) == null ? void 0 : m.page_background) == null ? void 0 : w.end,
848
848
  colors_page_background_angle_dev: (Z = (b = a.colors) == null ? void 0 : b.page_background) == null ? void 0 : Z.angle_deg,
849
849
  font_url: (ee = a.font) == null ? void 0 : ee.url,
@@ -851,13 +851,13 @@ function Ht(t) {
851
851
  }).execute();
852
852
  } catch {
853
853
  await t.updateTable("branding").set({
854
- ...o,
854
+ ...n,
855
855
  colors_primary: r == null ? void 0 : r.primary,
856
856
  colors_page_background_type: (ae = (te = a.colors) == null ? void 0 : te.page_background) == null ? void 0 : ae.type,
857
857
  colors_page_background_start: (ne = (re = a.colors) == null ? void 0 : re.page_background) == null ? void 0 : ne.start,
858
858
  colors_page_background_end: (se = (oe = a.colors) == null ? void 0 : oe.page_background) == null ? void 0 : se.end,
859
- colors_page_background_angle_dev: (de = (ie = a.colors) == null ? void 0 : ie.page_background) == null ? void 0 : de.angle_deg,
860
- font_url: (ce = a.font) == null ? void 0 : ce.url
859
+ colors_page_background_angle_dev: (ce = (ie = a.colors) == null ? void 0 : ie.page_background) == null ? void 0 : ce.angle_deg,
860
+ font_url: (de = a.font) == null ? void 0 : de.url
861
861
  }).where("tenant_id", "=", e).execute();
862
862
  }
863
863
  };
@@ -876,10 +876,10 @@ function Yt(t) {
876
876
  }) => {
877
877
  let r = t.selectFrom("hooks").where("hooks.tenant_id", "=", e);
878
878
  a.q && (r = O(t, r, a.q, ["url"]));
879
- const o = await r.offset(a.page * a.per_page).limit(a.per_page).selectAll().execute(), { count: s } = await r.select((d) => d.fn.countAll().as("count")).executeTakeFirstOrThrow();
879
+ const n = await r.offset(a.page * a.per_page).limit(a.per_page).selectAll().execute(), { count: s } = await r.select((c) => c.fn.countAll().as("count")).executeTakeFirstOrThrow();
880
880
  return {
881
- hooks: o.map((d) => {
882
- const { tenant_id: g, enabled: m, synchronous: w, ...b } = d;
881
+ hooks: n.map((c) => {
882
+ const { tenant_id: g, enabled: m, synchronous: w, ...b } = c;
883
883
  return _({
884
884
  ...b,
885
885
  enabled: !!m,
@@ -923,13 +923,13 @@ function ta(t) {
923
923
  }
924
924
  function aa(t) {
925
925
  return async (e, a, r) => {
926
- const n = {
926
+ const o = {
927
927
  ...r,
928
928
  updated_at: (/* @__PURE__ */ new Date()).toISOString(),
929
929
  enabled: r.enabled !== void 0 ? r.enabled ? 1 : 0 : void 0,
930
930
  synchronous: r.enabled !== void 0 ? r.synchronous ? 1 : 0 : void 0
931
931
  };
932
- return await t.updateTable("hooks").set(n).where("hooks.hook_id", "=", a).where("hooks.tenant_id", "=", e).execute(), !0;
932
+ return await t.updateTable("hooks").set(o).where("hooks.hook_id", "=", a).where("hooks.tenant_id", "=", e).execute(), !0;
933
933
  };
934
934
  }
935
935
  function ra(t) {
@@ -944,24 +944,24 @@ function ra(t) {
944
944
  function E(t, e = "", a = {}) {
945
945
  for (let r in t)
946
946
  if (Object.prototype.hasOwnProperty.call(t, r)) {
947
- const n = e ? `${e}_${r}` : r;
948
- typeof t[r] == "object" && t[r] !== null && !Array.isArray(t[r]) ? E(t[r], n, a) : a[n] = t[r];
947
+ const o = e ? `${e}_${r}` : r;
948
+ typeof t[r] == "object" && t[r] !== null && !Array.isArray(t[r]) ? E(t[r], o, a) : a[o] = t[r];
949
949
  }
950
950
  return a;
951
951
  }
952
952
  function na(t, e) {
953
953
  const a = {};
954
- for (const [r, n] of Object.entries(t)) {
955
- const o = e.find(
954
+ for (const [r, o] of Object.entries(t)) {
955
+ const n = e.find(
956
956
  (s) => r.startsWith(`${s}_`)
957
957
  );
958
- if (!o)
959
- a[r] = n;
958
+ if (!n)
959
+ a[r] = o;
960
960
  else {
961
- const s = r.slice(o.length + 1);
962
- a[o] = {
963
- ...a[o],
964
- [s]: n
961
+ const s = r.slice(n.length + 1);
962
+ a[n] = {
963
+ ...a[n],
964
+ [s]: o
965
965
  };
966
966
  }
967
967
  }
@@ -987,38 +987,38 @@ function ia(t) {
987
987
  return r ? _(r) : null;
988
988
  };
989
989
  }
990
- function da(t) {
990
+ function ca(t) {
991
991
  return async (e, a, r) => {
992
- const n = E({
992
+ const o = E({
993
993
  ...r,
994
994
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
995
995
  });
996
- return await t.updateTable("themes").set(n).where("themes.id", "=", a).where("themes.tenant_id", "=", e).execute(), !0;
996
+ return await t.updateTable("themes").set(o).where("themes.id", "=", a).where("themes.tenant_id", "=", e).execute(), !0;
997
997
  };
998
998
  }
999
- function ca(t) {
999
+ function da(t) {
1000
1000
  return {
1001
1001
  create: oa(t),
1002
1002
  get: ia(t),
1003
1003
  remove: sa(t),
1004
- update: da(t)
1004
+ update: ca(t)
1005
1005
  };
1006
1006
  }
1007
1007
  function la(t) {
1008
1008
  return async (e, a) => {
1009
- const r = (/* @__PURE__ */ new Date()).toISOString(), n = await t.selectFrom("login_sessions").where("login_sessions.expires_at", ">", r).where("login_sessions.id", "=", a).selectAll().executeTakeFirst();
1010
- return n ? Re.parse(
1011
- na(_(n), ["authParams"])
1009
+ const r = (/* @__PURE__ */ new Date()).toISOString(), o = await t.selectFrom("login_sessions").where("login_sessions.expires_at", ">", r).where("login_sessions.id", "=", a).selectAll().executeTakeFirst();
1010
+ return o ? Re.parse(
1011
+ na(_(o), ["authParams"])
1012
1012
  ) : null;
1013
1013
  };
1014
1014
  }
1015
1015
  function ua(t) {
1016
1016
  return async (e, a) => {
1017
- var n;
1017
+ var o;
1018
1018
  const r = {
1019
1019
  id: k(),
1020
1020
  ...a,
1021
- authorization_url: (n = a.authorization_url) == null ? void 0 : n.slice(0, 1024),
1021
+ authorization_url: (o = a.authorization_url) == null ? void 0 : o.slice(0, 1024),
1022
1022
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
1023
1023
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
1024
1024
  };
@@ -1085,38 +1085,38 @@ function ya(t) {
1085
1085
  return null;
1086
1086
  const {
1087
1087
  tenant_id: r,
1088
- credentials: n,
1089
- settings: o,
1088
+ credentials: o,
1089
+ settings: n,
1090
1090
  enabled: s,
1091
1091
  ...l
1092
1092
  } = a;
1093
1093
  return _({
1094
1094
  ...l,
1095
- credentials: JSON.parse(n),
1096
- settings: JSON.parse(o),
1095
+ credentials: JSON.parse(o),
1096
+ settings: JSON.parse(n),
1097
1097
  enabled: !!s
1098
1098
  });
1099
1099
  };
1100
1100
  }
1101
1101
  function wa(t) {
1102
1102
  return async (e, a) => {
1103
- const { credentials: r, settings: n, enabled: o, ...s } = a;
1103
+ const { credentials: r, settings: o, enabled: n, ...s } = a;
1104
1104
  await t.updateTable("email_providers").set({
1105
1105
  ...s,
1106
1106
  credentials: r ? JSON.stringify(r) : void 0,
1107
- settings: n ? JSON.stringify(n) : void 0,
1108
- enabled: o !== void 0 ? o ? 1 : 0 : void 0
1107
+ settings: o ? JSON.stringify(o) : void 0,
1108
+ enabled: n !== void 0 ? n ? 1 : 0 : void 0
1109
1109
  }).where("tenant_id", "=", e).execute();
1110
1110
  };
1111
1111
  }
1112
1112
  function va(t) {
1113
1113
  return async (e, a) => {
1114
- const { credentials: r, settings: n, enabled: o, ...s } = a;
1114
+ const { credentials: r, settings: o, enabled: n, ...s } = a;
1115
1115
  await t.insertInto("email_providers").values({
1116
1116
  ...s,
1117
- enabled: o ? 1 : 0,
1117
+ enabled: n ? 1 : 0,
1118
1118
  credentials: JSON.stringify(r),
1119
- settings: JSON.stringify(n),
1119
+ settings: JSON.stringify(o),
1120
1120
  tenant_id: e,
1121
1121
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
1122
1122
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
@@ -1161,13 +1161,13 @@ function xa(t) {
1161
1161
  }
1162
1162
  function Ta(t) {
1163
1163
  return async (e, a, r) => {
1164
- const n = {
1164
+ const o = {
1165
1165
  ...r,
1166
1166
  device: r.device ? JSON.stringify(r.device) : void 0,
1167
1167
  resource_servers: r.resource_servers ? JSON.stringify(r.resource_servers) : void 0,
1168
1168
  rotating: r.rotating ? 1 : 0
1169
1169
  };
1170
- return !!(await t.updateTable("refresh_tokens").set(n).where("tenant_id", "=", e).where("refresh_tokens.id", "=", a).execute()).length;
1170
+ return !!(await t.updateTable("refresh_tokens").set(o).where("tenant_id", "=", e).where("refresh_tokens.id", "=", a).execute()).length;
1171
1171
  };
1172
1172
  }
1173
1173
  function Sa(t) {
@@ -1178,22 +1178,22 @@ function Sa(t) {
1178
1178
  }) => {
1179
1179
  let r = t.selectFrom("refresh_tokens").where("refresh_tokens.tenant_id", "=", e);
1180
1180
  a.q && (r = O(t, r, a.q, ["token", "session_id"]));
1181
- let n = r;
1181
+ let o = r;
1182
1182
  if (a.sort && a.sort.sort_by) {
1183
- const { ref: d } = t.dynamic;
1184
- n = n.orderBy(
1185
- d(a.sort.sort_by),
1183
+ const { ref: c } = t.dynamic;
1184
+ o = o.orderBy(
1185
+ c(a.sort.sort_by),
1186
1186
  a.sort.sort_order
1187
1187
  );
1188
1188
  }
1189
- n = n.offset(a.page * a.per_page).limit(a.per_page);
1190
- const o = await n.selectAll().execute(), { count: s } = await r.select((d) => d.fn.countAll().as("count")).executeTakeFirstOrThrow(), l = x(s);
1191
- return {
1192
- refresh_tokens: o.map((d) => ({
1193
- ...d,
1194
- rotating: !!d.rotating,
1195
- device: d.device ? JSON.parse(d.device) : {},
1196
- resource_servers: d.resource_servers ? JSON.parse(d.resource_servers) : []
1189
+ o = o.offset(a.page * a.per_page).limit(a.per_page);
1190
+ const n = await o.selectAll().execute(), { count: s } = await r.select((c) => c.fn.countAll().as("count")).executeTakeFirstOrThrow(), l = x(s);
1191
+ return {
1192
+ refresh_tokens: n.map((c) => ({
1193
+ ...c,
1194
+ rotating: !!c.rotating,
1195
+ device: c.device ? JSON.parse(c.device) : {},
1196
+ resource_servers: c.resource_servers ? JSON.parse(c.resource_servers) : []
1197
1197
  })),
1198
1198
  start: a.page * a.per_page,
1199
1199
  limit: a.per_page,
@@ -1217,19 +1217,22 @@ function ka(t) {
1217
1217
  ).toISOString(), r = new Date(
1218
1218
  Date.now() - 1e3 * 60 * 60 * 24 * 30 * 3
1219
1219
  ).toISOString();
1220
- await t.deleteFrom("codes").where("created_at", "<", e).limit(1e5).execute(), await t.deleteFrom("login_sessions").where("created_at", "<", a).where("session_id", "is", null).limit(1e5).execute(), await t.deleteFrom("logs").where("date", "<", r).limit(1e5).execute(), await t.deleteFrom("refresh_tokens").where("expires_at", "<", a).limit(1e5).execute(), await t.deleteFrom("sessions").where(
1221
- (n) => n.and([
1222
- n.or([
1223
- n("sessions.expires_at", "<", a),
1224
- n("sessions.idle_expires_at", "<", a)
1225
- ]),
1226
- n(
1227
- "sessions.id",
1228
- "not in",
1229
- t.selectFrom("refresh_tokens").select("session_id")
1230
- )
1220
+ console.log("delete codes"), await t.deleteFrom("codes").where("created_at", "<", e).limit(1e5).execute(), console.log("delete sessions"), await t.deleteFrom("login_sessions").where("created_at", "<", a).where("session_id", "is", null).limit(1e5).execute(), console.log("delete logs"), await t.deleteFrom("logs").where("date", "<", r).limit(1e5).execute(), console.log("delete refresh tokens"), await t.deleteFrom("refresh_tokens").where("expires_at", "<", a).limit(1e5).execute(), console.log("delete sessions");
1221
+ const o = await t.selectFrom("sessions").select("id").where(
1222
+ (n) => n.or([
1223
+ n("expires_at", "<", a),
1224
+ n("idle_expires_at", "<", a)
1231
1225
  ])
1226
+ ).where(
1227
+ "id",
1228
+ "not in",
1229
+ t.selectFrom("refresh_tokens").select("session_id")
1232
1230
  ).limit(1e5).execute();
1231
+ o.length > 0 && await t.deleteFrom("sessions").where(
1232
+ "id",
1233
+ "in",
1234
+ o.map((n) => n.id)
1235
+ ).execute(), console.log("cleanup complete");
1233
1236
  };
1234
1237
  }
1235
1238
  function $a(t) {
@@ -1401,7 +1404,7 @@ class Ia {
1401
1404
  return this.nodeStack.pop(), p(a);
1402
1405
  }
1403
1406
  transformNodeImpl(e) {
1404
- return c(this, K)[e.kind](e);
1407
+ return d(this, K)[e.kind](e);
1405
1408
  }
1406
1409
  transformNodeList(e) {
1407
1410
  return e && p(e.map((a) => this.transformNode(a)));
@@ -2162,29 +2165,29 @@ class ja extends Ia {
2162
2165
  return super.transformNodeImpl(a);
2163
2166
  const r = u(this, f, we).call(this, a);
2164
2167
  for (const s of r)
2165
- c(this, S).add(s);
2166
- const n = u(this, f, ye).call(this, a);
2167
- for (const s of n)
2168
- c(this, T).add(s);
2169
- const o = super.transformNodeImpl(a);
2170
- for (const s of n)
2171
- c(this, T).delete(s);
2168
+ d(this, S).add(s);
2169
+ const o = u(this, f, ye).call(this, a);
2170
+ for (const s of o)
2171
+ d(this, T).add(s);
2172
+ const n = super.transformNodeImpl(a);
2173
+ for (const s of o)
2174
+ d(this, T).delete(s);
2172
2175
  for (const s of r)
2173
- c(this, S).delete(s);
2174
- return o;
2176
+ d(this, S).delete(s);
2177
+ return n;
2175
2178
  }
2176
2179
  transformSchemableIdentifier(a) {
2177
2180
  const r = super.transformSchemableIdentifier(a);
2178
- return r.schema || !c(this, T).has(a.identifier.name) ? r : {
2181
+ return r.schema || !d(this, T).has(a.identifier.name) ? r : {
2179
2182
  ...r,
2180
- schema: J.create(c(this, P))
2183
+ schema: J.create(d(this, P))
2181
2184
  };
2182
2185
  }
2183
2186
  transformReferences(a) {
2184
2187
  const r = super.transformReferences(a);
2185
2188
  return r.table.table.schema ? r : {
2186
2189
  ...r,
2187
- table: U.createWithSchema(c(this, P), r.table.table.identifier.name)
2190
+ table: U.createWithSchema(d(this, P), r.table.table.identifier.name)
2188
2191
  };
2189
2192
  }
2190
2193
  }
@@ -2193,25 +2196,25 @@ P = new WeakMap(), T = new WeakMap(), S = new WeakMap(), f = new WeakSet(), ge =
2193
2196
  }, ye = function(a) {
2194
2197
  const r = /* @__PURE__ */ new Set();
2195
2198
  if ("name" in a && a.name && W.is(a.name) && u(this, f, q).call(this, a.name, r), "from" in a && a.from)
2196
- for (const n of a.from.froms)
2197
- u(this, f, $).call(this, n, r);
2199
+ for (const o of a.from.froms)
2200
+ u(this, f, $).call(this, o, r);
2198
2201
  if ("into" in a && a.into && u(this, f, $).call(this, a.into, r), "table" in a && a.table && u(this, f, $).call(this, a.table, r), "joins" in a && a.joins)
2199
- for (const n of a.joins)
2200
- u(this, f, $).call(this, n.table, r);
2202
+ for (const o of a.joins)
2203
+ u(this, f, $).call(this, o.table, r);
2201
2204
  return "using" in a && a.using && u(this, f, $).call(this, a.using, r), r;
2202
2205
  }, we = function(a) {
2203
2206
  const r = /* @__PURE__ */ new Set();
2204
2207
  return "with" in a && a.with && u(this, f, ve).call(this, a.with, r), r;
2205
2208
  }, $ = function(a, r) {
2206
- const n = U.is(a) ? a : Da.is(a) && U.is(a.node) ? a.node : null;
2207
- n && u(this, f, q).call(this, n.table, r);
2209
+ const o = U.is(a) ? a : Da.is(a) && U.is(a.node) ? a.node : null;
2210
+ o && u(this, f, q).call(this, o.table, r);
2208
2211
  }, q = function(a, r) {
2209
- const n = a.identifier.name;
2210
- !c(this, T).has(n) && !c(this, S).has(n) && r.add(n);
2212
+ const o = a.identifier.name;
2213
+ !d(this, T).has(o) && !d(this, S).has(o) && r.add(o);
2211
2214
  }, ve = function(a, r) {
2212
- for (const n of a.expressions) {
2213
- const o = n.name.table.table.identifier.name;
2214
- c(this, S).has(o) || r.add(o);
2215
+ for (const o of a.expressions) {
2216
+ const n = o.name.table.table.identifier.name;
2217
+ d(this, S).has(n) || r.add(n);
2215
2218
  }
2216
2219
  };
2217
2220
  var L;
@@ -2221,7 +2224,7 @@ class Ma {
2221
2224
  M(this, L, new ja(e));
2222
2225
  }
2223
2226
  transformQuery(e) {
2224
- return c(this, L).transformNode(e.node);
2227
+ return d(this, L).transformNode(e.node);
2225
2228
  }
2226
2229
  async transformResult(e) {
2227
2230
  return e.result;
@@ -2250,13 +2253,13 @@ class Ne {
2250
2253
  * The returned array is sorted by migration name.
2251
2254
  */
2252
2255
  async getMigrations() {
2253
- const e = await u(this, i, I).call(this, c(this, i, N)) ? await c(this, h).db.withPlugin(c(this, i, C)).selectFrom(c(this, i, N)).select(["name", "timestamp"]).execute() : [];
2254
- return (await u(this, i, X).call(this)).map(({ name: r, ...n }) => {
2255
- const o = e.find((s) => s.name === r);
2256
+ const e = await u(this, i, I).call(this, d(this, i, N)) ? await d(this, h).db.withPlugin(d(this, i, C)).selectFrom(d(this, i, N)).select(["name", "timestamp"]).execute() : [];
2257
+ return (await u(this, i, X).call(this)).map(({ name: r, ...o }) => {
2258
+ const n = e.find((s) => s.name === r);
2256
2259
  return {
2257
2260
  name: r,
2258
- migration: n,
2259
- executedAt: o ? new Date(o.timestamp) : void 0
2261
+ migration: o,
2262
+ executedAt: n ? new Date(n.timestamp) : void 0
2260
2263
  };
2261
2264
  });
2262
2265
  }
@@ -2334,16 +2337,16 @@ class Ne {
2334
2337
  * ```
2335
2338
  */
2336
2339
  async migrateTo(e) {
2337
- return u(this, i, F).call(this, ({ migrations: a, executedMigrations: r, pendingMigrations: n }) => {
2340
+ return u(this, i, F).call(this, ({ migrations: a, executedMigrations: r, pendingMigrations: o }) => {
2338
2341
  if (e === za)
2339
2342
  return { direction: "Down", step: 1 / 0 };
2340
2343
  if (!a.find((l) => l.name === e))
2341
2344
  throw new Error(`migration "${e}" doesn't exist`);
2342
- const o = r.indexOf(e), s = n.findIndex((l) => l.name === e);
2343
- if (o !== -1)
2345
+ const n = r.indexOf(e), s = o.findIndex((l) => l.name === e);
2346
+ if (n !== -1)
2344
2347
  return {
2345
2348
  direction: "Down",
2346
- step: r.length - o - 1
2349
+ step: r.length - n - 1
2347
2350
  };
2348
2351
  if (s !== -1)
2349
2352
  return { direction: "Up", step: s + 1 };
@@ -2392,161 +2395,161 @@ h = new WeakMap(), i = new WeakSet(), F = async function(e) {
2392
2395
  return a instanceof Q ? a.resultSet : { error: a };
2393
2396
  }
2394
2397
  }, v = function() {
2395
- return c(this, h).migrationTableSchema;
2398
+ return d(this, h).migrationTableSchema;
2396
2399
  }, N = function() {
2397
- return c(this, h).migrationTableName ?? Aa;
2400
+ return d(this, h).migrationTableName ?? Aa;
2398
2401
  }, D = function() {
2399
- return c(this, h).migrationLockTableName ?? _e;
2402
+ return d(this, h).migrationLockTableName ?? _e;
2400
2403
  }, Ce = function() {
2401
- return c(this, h).allowUnorderedMigrations ?? La;
2404
+ return d(this, h).allowUnorderedMigrations ?? La;
2402
2405
  }, C = function() {
2403
- return c(this, i, v) ? new Ma(c(this, i, v)) : new Fa();
2406
+ return d(this, i, v) ? new Ma(d(this, i, v)) : new Fa();
2404
2407
  }, be = async function() {
2405
2408
  await u(this, i, xe).call(this), await u(this, i, Te).call(this), await u(this, i, Se).call(this), await u(this, i, Oe).call(this);
2406
2409
  }, xe = async function() {
2407
- if (c(this, i, v) && !await u(this, i, G).call(this))
2410
+ if (d(this, i, v) && !await u(this, i, G).call(this))
2408
2411
  try {
2409
- await u(this, i, A).call(this, c(this, h).db.schema.createSchema(c(this, i, v)));
2412
+ await u(this, i, A).call(this, d(this, h).db.schema.createSchema(d(this, i, v)));
2410
2413
  } catch (e) {
2411
2414
  if (!await u(this, i, G).call(this))
2412
2415
  throw e;
2413
2416
  }
2414
2417
  }, Te = async function() {
2415
- if (!await u(this, i, I).call(this, c(this, i, N)))
2418
+ if (!await u(this, i, I).call(this, d(this, i, N)))
2416
2419
  try {
2417
- c(this, i, v) && await u(this, i, A).call(this, c(this, h).db.schema.createSchema(c(this, i, v))), await u(this, i, A).call(this, c(this, h).db.schema.withPlugin(c(this, i, C)).createTable(c(this, i, N)).addColumn("name", "varchar(255)", (e) => e.notNull().primaryKey()).addColumn("timestamp", "varchar(255)", (e) => e.notNull()));
2420
+ d(this, i, v) && await u(this, i, A).call(this, d(this, h).db.schema.createSchema(d(this, i, v))), await u(this, i, A).call(this, d(this, h).db.schema.withPlugin(d(this, i, C)).createTable(d(this, i, N)).addColumn("name", "varchar(255)", (e) => e.notNull().primaryKey()).addColumn("timestamp", "varchar(255)", (e) => e.notNull()));
2418
2421
  } catch (e) {
2419
- if (!await u(this, i, I).call(this, c(this, i, N)))
2422
+ if (!await u(this, i, I).call(this, d(this, i, N)))
2420
2423
  throw e;
2421
2424
  }
2422
2425
  }, Se = async function() {
2423
- if (!await u(this, i, I).call(this, c(this, i, D)))
2426
+ if (!await u(this, i, I).call(this, d(this, i, D)))
2424
2427
  try {
2425
- await u(this, i, A).call(this, c(this, h).db.schema.withPlugin(c(this, i, C)).createTable(c(this, i, D)).addColumn("id", "varchar(255)", (e) => e.notNull().primaryKey()).addColumn("is_locked", "integer", (e) => e.notNull().defaultTo(0)));
2428
+ await u(this, i, A).call(this, d(this, h).db.schema.withPlugin(d(this, i, C)).createTable(d(this, i, D)).addColumn("id", "varchar(255)", (e) => e.notNull().primaryKey()).addColumn("is_locked", "integer", (e) => e.notNull().defaultTo(0)));
2426
2429
  } catch (e) {
2427
- if (!await u(this, i, I).call(this, c(this, i, D)))
2430
+ if (!await u(this, i, I).call(this, d(this, i, D)))
2428
2431
  throw e;
2429
2432
  }
2430
2433
  }, Oe = async function() {
2431
2434
  if (!await u(this, i, H).call(this))
2432
2435
  try {
2433
- await c(this, h).db.withPlugin(c(this, i, C)).insertInto(c(this, i, D)).values({ id: B, is_locked: 0 }).execute();
2436
+ await d(this, h).db.withPlugin(d(this, i, C)).insertInto(d(this, i, D)).values({ id: B, is_locked: 0 }).execute();
2434
2437
  } catch (e) {
2435
2438
  if (!await u(this, i, H).call(this))
2436
2439
  throw e;
2437
2440
  }
2438
2441
  }, G = async function() {
2439
- return (await c(this, h).db.introspection.getSchemas()).some((a) => a.name === c(this, i, v));
2442
+ return (await d(this, h).db.introspection.getSchemas()).some((a) => a.name === d(this, i, v));
2440
2443
  }, I = async function(e) {
2441
- const a = c(this, i, v);
2442
- return (await c(this, h).db.introspection.getTables({
2444
+ const a = d(this, i, v);
2445
+ return (await d(this, h).db.introspection.getTables({
2443
2446
  withInternalKyselyTables: !0
2444
- })).some((n) => n.name === e && (!a || n.schema === a));
2447
+ })).some((o) => o.name === e && (!a || o.schema === a));
2445
2448
  }, H = async function() {
2446
- return !!await c(this, h).db.withPlugin(c(this, i, C)).selectFrom(c(this, i, D)).where("id", "=", B).select("id").executeTakeFirst();
2449
+ return !!await d(this, h).db.withPlugin(d(this, i, C)).selectFrom(d(this, i, D)).where("id", "=", B).select("id").executeTakeFirst();
2447
2450
  }, ke = async function(e) {
2448
- const a = c(this, h).db.getExecutor().adapter, r = p({
2449
- lockTable: c(this, h).migrationLockTableName ?? _e,
2451
+ const a = d(this, h).db.getExecutor().adapter, r = p({
2452
+ lockTable: d(this, h).migrationLockTableName ?? _e,
2450
2453
  lockRowId: B,
2451
- lockTableSchema: c(this, h).migrationTableSchema
2452
- }), n = async (o) => {
2454
+ lockTableSchema: d(this, h).migrationTableSchema
2455
+ }), o = async (n) => {
2453
2456
  try {
2454
- await a.acquireMigrationLock(o, r);
2455
- const s = await u(this, i, $e).call(this, o);
2457
+ await a.acquireMigrationLock(n, r);
2458
+ const s = await u(this, i, $e).call(this, n);
2456
2459
  if (s.migrations.length === 0)
2457
2460
  return { results: [] };
2458
- const { direction: l, step: d } = e(s);
2459
- return d <= 0 ? { results: [] } : l === "Down" ? await u(this, i, Me).call(this, o, s, d) : l === "Up" ? await u(this, i, Fe).call(this, o, s, d) : { results: [] };
2461
+ const { direction: l, step: c } = e(s);
2462
+ return c <= 0 ? { results: [] } : l === "Down" ? await u(this, i, Me).call(this, n, s, c) : l === "Up" ? await u(this, i, Fe).call(this, n, s, c) : { results: [] };
2460
2463
  } finally {
2461
- await a.releaseMigrationLock(o, r);
2464
+ await a.releaseMigrationLock(n, r);
2462
2465
  }
2463
2466
  };
2464
- return a.supportsTransactionalDdl ? c(this, h).db.transaction().execute(n) : c(this, h).db.connection().execute(n);
2467
+ return a.supportsTransactionalDdl ? d(this, h).db.transaction().execute(o) : d(this, h).db.connection().execute(o);
2465
2468
  }, $e = async function(e) {
2466
2469
  const a = await u(this, i, X).call(this), r = await u(this, i, Ie).call(this, e);
2467
- u(this, i, Pe).call(this, a, r), c(this, i, Ce) || u(this, i, je).call(this, a, r);
2468
- const n = u(this, i, De).call(this, a, r);
2470
+ u(this, i, Pe).call(this, a, r), d(this, i, Ce) || u(this, i, je).call(this, a, r);
2471
+ const o = u(this, i, De).call(this, a, r);
2469
2472
  return p({
2470
2473
  migrations: a,
2471
2474
  executedMigrations: r,
2472
2475
  lastMigration: $a(r),
2473
- pendingMigrations: n
2476
+ pendingMigrations: o
2474
2477
  });
2475
2478
  }, De = function(e, a) {
2476
2479
  return e.filter((r) => !a.includes(r.name));
2477
2480
  }, X = async function() {
2478
- const e = await c(this, h).provider.getMigrations();
2481
+ const e = await d(this, h).provider.getMigrations();
2479
2482
  return Object.keys(e).sort().map((a) => ({
2480
2483
  ...e[a],
2481
2484
  name: a
2482
2485
  }));
2483
2486
  }, Ie = async function(e) {
2484
- return (await e.withPlugin(c(this, i, C)).selectFrom(c(this, i, N)).select("name").orderBy(["timestamp", "name"]).execute()).map((r) => r.name);
2487
+ return (await e.withPlugin(d(this, i, C)).selectFrom(d(this, i, N)).select("name").orderBy(["timestamp", "name"]).execute()).map((r) => r.name);
2485
2488
  }, Pe = function(e, a) {
2486
2489
  for (const r of a)
2487
- if (!e.some((n) => n.name === r))
2490
+ if (!e.some((o) => o.name === r))
2488
2491
  throw new Error(`corrupted migrations: previously executed migration ${r} is missing`);
2489
2492
  }, je = function(e, a) {
2490
2493
  for (let r = 0; r < a.length; ++r)
2491
2494
  if (e[r].name !== a[r])
2492
2495
  throw new Error(`corrupted migrations: expected previously executed migration ${a[r]} to be at index ${r} but ${e[r].name} was found in its place. New migrations must always have a name that comes alphabetically after the last executed migration.`);
2493
2496
  }, Me = async function(e, a, r) {
2494
- const n = a.executedMigrations.slice().reverse().slice(0, r).map((s) => a.migrations.find((l) => l.name === s)), o = n.map((s) => ({
2497
+ const o = a.executedMigrations.slice().reverse().slice(0, r).map((s) => a.migrations.find((l) => l.name === s)), n = o.map((s) => ({
2495
2498
  migrationName: s.name,
2496
2499
  direction: "Down",
2497
2500
  status: "NotExecuted"
2498
2501
  }));
2499
- for (let s = 0; s < o.length; ++s) {
2500
- const l = n[s];
2502
+ for (let s = 0; s < n.length; ++s) {
2503
+ const l = o[s];
2501
2504
  try {
2502
- l.down && (await l.down(e), await e.withPlugin(c(this, i, C)).deleteFrom(c(this, i, N)).where("name", "=", l.name).execute(), o[s] = {
2505
+ l.down && (await l.down(e), await e.withPlugin(d(this, i, C)).deleteFrom(d(this, i, N)).where("name", "=", l.name).execute(), n[s] = {
2503
2506
  migrationName: l.name,
2504
2507
  direction: "Down",
2505
2508
  status: "Success"
2506
2509
  });
2507
- } catch (d) {
2508
- throw o[s] = {
2510
+ } catch (c) {
2511
+ throw n[s] = {
2509
2512
  migrationName: l.name,
2510
2513
  direction: "Down",
2511
2514
  status: "Error"
2512
2515
  }, new Q({
2513
- error: d,
2514
- results: o
2516
+ error: c,
2517
+ results: n
2515
2518
  });
2516
2519
  }
2517
2520
  }
2518
- return { results: o };
2521
+ return { results: n };
2519
2522
  }, Fe = async function(e, a, r) {
2520
- const o = a.pendingMigrations.slice(0, r).map((s) => ({
2523
+ const n = a.pendingMigrations.slice(0, r).map((s) => ({
2521
2524
  migrationName: s.name,
2522
2525
  direction: "Up",
2523
2526
  status: "NotExecuted"
2524
2527
  }));
2525
- for (let s = 0; s < o.length; s++) {
2528
+ for (let s = 0; s < n.length; s++) {
2526
2529
  const l = a.pendingMigrations[s];
2527
2530
  try {
2528
- await l.up(e), await e.withPlugin(c(this, i, C)).insertInto(c(this, i, N)).values({
2531
+ await l.up(e), await e.withPlugin(d(this, i, C)).insertInto(d(this, i, N)).values({
2529
2532
  name: l.name,
2530
2533
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
2531
- }).execute(), o[s] = {
2534
+ }).execute(), n[s] = {
2532
2535
  migrationName: l.name,
2533
2536
  direction: "Up",
2534
2537
  status: "Success"
2535
2538
  };
2536
- } catch (d) {
2537
- throw o[s] = {
2539
+ } catch (c) {
2540
+ throw n[s] = {
2538
2541
  migrationName: l.name,
2539
2542
  direction: "Up",
2540
2543
  status: "Error"
2541
2544
  }, new Q({
2542
- error: d,
2543
- results: o
2545
+ error: c,
2546
+ results: n
2544
2547
  });
2545
2548
  }
2546
2549
  }
2547
- return { results: o };
2550
+ return { results: n };
2548
2551
  }, A = async function(e) {
2549
- c(this, h).db.getExecutor().adapter.supportsCreateIfNotExists && (e = e.ifNotExists()), await e.execute();
2552
+ d(this, h).db.getExecutor().adapter.supportsCreateIfNotExists && (e = e.ifNotExists()), await e.execute();
2550
2553
  };
2551
2554
  var z;
2552
2555
  class Q extends Error {
@@ -2556,7 +2559,7 @@ class Q extends Error {
2556
2559
  M(this, z, a);
2557
2560
  }
2558
2561
  get resultSet() {
2559
- return c(this, z);
2562
+ return d(this, z);
2560
2563
  }
2561
2564
  }
2562
2565
  z = new WeakMap();
@@ -2751,12 +2754,12 @@ async function sr(t) {
2751
2754
  }
2752
2755
  async function ir(t) {
2753
2756
  }
2754
- const dr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2757
+ const cr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2755
2758
  __proto__: null,
2756
2759
  down: ir,
2757
2760
  up: sr
2758
2761
  }, Symbol.toStringTag, { value: "Module" }));
2759
- async function cr(t) {
2762
+ async function dr(t) {
2760
2763
  await t.schema.alterTable("passwords").addColumn(
2761
2764
  "password",
2762
2765
  "varchar(255)",
@@ -2770,7 +2773,7 @@ async function lr(t) {
2770
2773
  const ur = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2771
2774
  __proto__: null,
2772
2775
  down: lr,
2773
- up: cr
2776
+ up: dr
2774
2777
  }, Symbol.toStringTag, { value: "Module" }));
2775
2778
  async function mr(t) {
2776
2779
  }
@@ -2943,12 +2946,12 @@ const on = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2943
2946
  async function sn(t) {
2944
2947
  await t.schema.alterTable("logs").addColumn("user_name", "varchar(255)").execute(), await t.schema.alterTable("logs").addColumn("auth0_client", "varchar(255)").execute(), await t.schema.alterTable("logs").addColumn("isMobile", "boolean").execute(), await t.schema.alterTable("logs").addColumn("connection", "varchar(255)").execute(), await t.schema.alterTable("logs").addColumn("connection_id", "varchar(255)").execute(), await t.schema.alterTable("logs").addColumn("audience", "varchar(255)").execute(), await t.schema.alterTable("logs").addColumn("scope", "varchar(255)").execute(), await t.schema.alterTable("logs").addColumn("strategy", "varchar(255)").execute(), await t.schema.alterTable("logs").addColumn("strategy_type", "varchar(255)").execute(), await t.schema.alterTable("logs").addColumn("hostname", "varchar(255)").execute(), await t.schema.alterTable("logs").addColumn("session_connection", "varchar(255)").execute();
2945
2948
  }
2946
- async function dn(t) {
2949
+ async function cn(t) {
2947
2950
  await t.schema.alterTable("logs").dropColumn("user_name").execute(), await t.schema.alterTable("logs").dropColumn("auth0_client").execute(), await t.schema.alterTable("logs").dropColumn("isMobile").execute(), await t.schema.alterTable("logs").dropColumn("connection").execute(), await t.schema.alterTable("logs").dropColumn("connection_id").execute(), await t.schema.alterTable("logs").dropColumn("audience").execute(), await t.schema.alterTable("logs").dropColumn("scope").execute(), await t.schema.alterTable("logs").dropColumn("strategy").execute(), await t.schema.alterTable("logs").dropColumn("strategy_type").execute(), await t.schema.alterTable("logs").dropColumn("hostname").execute(), await t.schema.alterTable("logs").dropColumn("session_connection").execute();
2948
2951
  }
2949
- const cn = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2952
+ const dn = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2950
2953
  __proto__: null,
2951
- down: dn,
2954
+ down: cn,
2952
2955
  up: sn
2953
2956
  }, Symbol.toStringTag, { value: "Module" }));
2954
2957
  async function ln(t) {
@@ -3396,16 +3399,16 @@ const is = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3396
3399
  down: ss,
3397
3400
  up: os
3398
3401
  }, Symbol.toStringTag, { value: "Module" }));
3399
- async function ds(t) {
3402
+ async function cs(t) {
3400
3403
  await t.schema.alterTable("logins").addColumn("authParams_prompt", "varchar(16)").execute();
3401
3404
  }
3402
- async function cs(t) {
3405
+ async function ds(t) {
3403
3406
  await t.schema.alterTable("logins").dropColumn("authParams_prompt").execute();
3404
3407
  }
3405
3408
  const ls = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3406
3409
  __proto__: null,
3407
- down: cs,
3408
- up: ds
3410
+ down: ds,
3411
+ up: cs
3409
3412
  }, Symbol.toStringTag, { value: "Module" }));
3410
3413
  async function us(t) {
3411
3414
  }
@@ -3675,7 +3678,7 @@ const ni = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3675
3678
  m5_userProfile: Za,
3676
3679
  m6_sessions: ar,
3677
3680
  m7_passwords: or,
3678
- m8_logsTableNewFields: dr,
3681
+ m8_logsTableNewFields: cr,
3679
3682
  m9_passwordTableNewField: ur,
3680
3683
  n01_codesTable: _r,
3681
3684
  n11_universalLoginSession: gr,
@@ -3693,7 +3696,7 @@ const ni = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3693
3696
  n23_dropUsersFields: Zr,
3694
3697
  n24_logsIndexes: an,
3695
3698
  n25_logDescMaxLength: on,
3696
- n26_logsTableExtraFields: cn,
3699
+ n26_logsTableExtraFields: dn,
3697
3700
  n27_usersTableNameIndex: mn,
3698
3701
  n28_usersEmailConstrain: fn,
3699
3702
  n29_increaseOtpStateLength: yn,
@@ -3747,27 +3750,27 @@ const ni = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3747
3750
  n78_login_sessions: ti,
3748
3751
  n79_drop_sessions_2: ni
3749
3752
  };
3750
- async function ci(t, e = !1) {
3753
+ async function di(t, e = !1) {
3751
3754
  e && console.log("migrating...");
3752
3755
  const a = new Ae(Le), r = new Ne({
3753
3756
  db: t,
3754
3757
  provider: a
3755
- }), { error: n, results: o } = await r.migrateToLatest();
3756
- if (o == null || o.forEach((s) => {
3758
+ }), { error: o, results: n } = await r.migrateToLatest();
3759
+ if (n == null || n.forEach((s) => {
3757
3760
  s.status === "Success" ? e && console.log(
3758
3761
  `migration "${s.migrationName}" was executed successfully`
3759
3762
  ) : s.status === "Error" && console.error(`failed to execute migration "${s.migrationName}"`);
3760
- }), n)
3761
- throw console.error("failed to migrate"), console.error(n), n;
3763
+ }), o)
3764
+ throw console.error("failed to migrate"), console.error(o), o;
3762
3765
  }
3763
3766
  async function li(t) {
3764
3767
  console.log("migrating...");
3765
3768
  const e = new Ae(Le), a = new Ne({
3766
3769
  db: t,
3767
3770
  provider: e
3768
- }), { error: r, results: n } = await a.migrateDown();
3769
- if (n == null || n.forEach((o) => {
3770
- o.status === "Success" ? console.log(`migration "${o.migrationName}" was reverted successfully`) : o.status === "Error" && console.error(`failed to execute migration "${o.migrationName}"`);
3771
+ }), { error: r, results: o } = await a.migrateDown();
3772
+ if (o == null || o.forEach((n) => {
3773
+ n.status === "Success" ? console.log(`migration "${n.migrationName}" was reverted successfully`) : n.status === "Error" && console.error(`failed to execute migration "${n.migrationName}"`);
3771
3774
  }), r)
3772
3775
  throw console.error("failed to migrate"), console.error(r), r;
3773
3776
  }
@@ -3784,18 +3787,18 @@ function ui(t) {
3784
3787
  hooks: ra(t),
3785
3788
  keys: Rt(t),
3786
3789
  loginSessions: _a(t),
3787
- logs: ct(t),
3790
+ logs: dt(t),
3788
3791
  passwords: wt(t),
3789
3792
  promptSettings: ga(t),
3790
3793
  refreshTokens: Oa(t),
3791
3794
  sessions: ft(t),
3792
3795
  tenants: nt(t),
3793
- themes: ca(t),
3796
+ themes: da(t),
3794
3797
  users: Xe(t)
3795
3798
  };
3796
3799
  }
3797
3800
  export {
3798
3801
  ui as default,
3799
3802
  li as migrateDown,
3800
- ci as migrateToLatest
3803
+ di as migrateToLatest
3801
3804
  };