better-auth-instantdb 1.3.1 → 1.3.3

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.
package/dist/index.js CHANGED
@@ -1,138 +1,138 @@
1
- const k = {
1
+ const V = {
2
2
  Remove: "remove",
3
3
  Replace: "replace",
4
4
  Add: "add"
5
- }, Pe = /* @__PURE__ */ Symbol.for("__MUTATIVE_PROXY_DRAFT__"), de = Symbol.iterator, K = {
5
+ }, Xe = /* @__PURE__ */ Symbol.for("__MUTATIVE_PROXY_DRAFT__"), $e = Symbol.iterator, Z = {
6
6
  mutable: "mutable",
7
7
  immutable: "immutable"
8
- }, Ae = {};
9
- function ae(e, t) {
8
+ }, ke = {};
9
+ function ye(e, t) {
10
10
  return e instanceof Map ? e.has(t) : Object.prototype.hasOwnProperty.call(e, t);
11
11
  }
12
- function Me(e, t) {
12
+ function Ue(e, t) {
13
13
  if (t in e) {
14
14
  let n = Reflect.getPrototypeOf(e);
15
15
  for (; n; ) {
16
- const r = Reflect.getOwnPropertyDescriptor(n, t);
17
- if (r)
18
- return r;
16
+ const i = Reflect.getOwnPropertyDescriptor(n, t);
17
+ if (i)
18
+ return i;
19
19
  n = Reflect.getPrototypeOf(n);
20
20
  }
21
21
  }
22
22
  }
23
- function ze(e) {
23
+ function Ze(e) {
24
24
  return Object.getPrototypeOf(e) === Set.prototype;
25
25
  }
26
- function qe(e) {
26
+ function Qe(e) {
27
27
  return Object.getPrototypeOf(e) === Map.prototype;
28
28
  }
29
- function F(e) {
29
+ function W(e) {
30
30
  var t;
31
31
  return (t = e.copy) !== null && t !== void 0 ? t : e.original;
32
32
  }
33
- function ye(e) {
34
- return !!v(e);
33
+ function ve(e) {
34
+ return !!T(e);
35
35
  }
36
- function v(e) {
37
- return typeof e != "object" ? null : e?.[Pe];
36
+ function T(e) {
37
+ return typeof e != "object" ? null : e?.[Xe];
38
38
  }
39
- function Ie(e) {
39
+ function Ce(e) {
40
40
  var t;
41
- const n = v(e);
41
+ const n = T(e);
42
42
  return n ? (t = n.copy) !== null && t !== void 0 ? t : n.original : e;
43
43
  }
44
- function Q(e, t) {
44
+ function ce(e, t) {
45
45
  if (!e || typeof e != "object")
46
46
  return !1;
47
47
  let n;
48
- return Object.getPrototypeOf(e) === Object.prototype || Array.isArray(e) || e instanceof Map || e instanceof Set || !!t?.mark && ((n = t.mark(e, K)) === K.immutable || typeof n == "function");
48
+ return Object.getPrototypeOf(e) === Object.prototype || Array.isArray(e) || e instanceof Map || e instanceof Set || !!t?.mark && ((n = t.mark(e, Z)) === Z.immutable || typeof n == "function");
49
49
  }
50
- function Ve(e, t = []) {
50
+ function et(e, t = []) {
51
51
  if (Object.hasOwnProperty.call(e, "key")) {
52
- const n = e.parent.copy, r = v(H(n, e.key));
53
- if (r !== null && r?.original !== e.original)
52
+ const n = e.parent.copy, i = T(ie(n, e.key));
53
+ if (i !== null && i?.original !== e.original)
54
54
  return null;
55
- const i = e.parent.type === 3, o = i ? Array.from(e.parent.setMap.keys()).indexOf(e.key) : e.key;
56
- if (!(i && n.size > o || ae(n, o)))
55
+ const r = e.parent.type === 3, s = r ? Array.from(e.parent.setMap.keys()).indexOf(e.key) : e.key;
56
+ if (!(r && n.size > s || ye(n, s)))
57
57
  return null;
58
- t.push(o);
58
+ t.push(s);
59
59
  }
60
60
  if (e.parent)
61
- return Ve(e.parent, t);
61
+ return et(e.parent, t);
62
62
  t.reverse();
63
63
  try {
64
- Ze(e.copy, t);
64
+ dt(e.copy, t);
65
65
  } catch {
66
66
  return null;
67
67
  }
68
68
  return t;
69
69
  }
70
- function le(e) {
70
+ function we(e) {
71
71
  return Array.isArray(e) ? 1 : e instanceof Map ? 2 : e instanceof Set ? 3 : 0;
72
72
  }
73
- function H(e, t) {
74
- return le(e) === 2 ? e.get(t) : e[t];
73
+ function ie(e, t) {
74
+ return we(e) === 2 ? e.get(t) : e[t];
75
75
  }
76
- function Te(e, t, n) {
77
- le(e) === 2 ? e.set(t, n) : e[t] = n;
76
+ function Le(e, t, n) {
77
+ we(e) === 2 ? e.set(t, n) : e[t] = n;
78
78
  }
79
- function we(e, t) {
80
- const n = v(e);
81
- return (n ? F(n) : e)[t];
79
+ function Se(e, t) {
80
+ const n = T(e);
81
+ return (n ? W(n) : e)[t];
82
82
  }
83
- function Z(e, t) {
83
+ function ae(e, t) {
84
84
  return e === t ? e !== 0 || 1 / e === 1 / t : e !== e && t !== t;
85
85
  }
86
- function X(e, t) {
86
+ function se(e, t) {
87
87
  return t ? e : [""].concat(e).map((n) => {
88
- const r = `${n}`;
89
- return r.indexOf("/") === -1 && r.indexOf("~") === -1 ? r : r.replace(/~/g, "~0").replace(/\//g, "~1");
88
+ const i = `${n}`;
89
+ return i.indexOf("/") === -1 && i.indexOf("~") === -1 ? i : i.replace(/~/g, "~0").replace(/\//g, "~1");
90
90
  }).join("/");
91
91
  }
92
- function Ze(e, t) {
92
+ function dt(e, t) {
93
93
  for (let n = 0; n < t.length - 1; n += 1) {
94
- const r = t[n];
95
- if (e = H(le(e) === 3 ? Array.from(e) : e, r), typeof e != "object")
94
+ const i = t[n];
95
+ if (e = ie(we(e) === 3 ? Array.from(e) : e, i), typeof e != "object")
96
96
  throw new Error(`Cannot resolve patch at '${t.join("/")}'.`);
97
97
  }
98
98
  return e;
99
99
  }
100
- function Qe(e) {
100
+ function lt(e) {
101
101
  const t = Object.create(Object.getPrototypeOf(e));
102
102
  return Reflect.ownKeys(e).forEach((n) => {
103
- let r = Reflect.getOwnPropertyDescriptor(e, n);
104
- if (r.enumerable && r.configurable && r.writable) {
103
+ let i = Reflect.getOwnPropertyDescriptor(e, n);
104
+ if (i.enumerable && i.configurable && i.writable) {
105
105
  t[n] = e[n];
106
106
  return;
107
107
  }
108
- r.writable || (r.writable = !0, r.configurable = !0), (r.get || r.set) && (r = {
108
+ i.writable || (i.writable = !0, i.configurable = !0), (i.get || i.set) && (i = {
109
109
  configurable: !0,
110
110
  writable: !0,
111
- enumerable: r.enumerable,
111
+ enumerable: i.enumerable,
112
112
  value: e[n]
113
- }), Reflect.defineProperty(t, n, r);
113
+ }), Reflect.defineProperty(t, n, i);
114
114
  }), t;
115
115
  }
116
- const et = Object.prototype.propertyIsEnumerable;
117
- function tt(e, t) {
116
+ const ft = Object.prototype.propertyIsEnumerable;
117
+ function pt(e, t) {
118
118
  let n;
119
119
  if (Array.isArray(e))
120
120
  return Array.prototype.concat.call(e);
121
121
  if (e instanceof Set) {
122
- if (!ze(e)) {
123
- const r = Object.getPrototypeOf(e).constructor;
124
- return new r(e.values());
122
+ if (!Ze(e)) {
123
+ const i = Object.getPrototypeOf(e).constructor;
124
+ return new i(e.values());
125
125
  }
126
126
  return Set.prototype.difference ? Set.prototype.difference.call(e, /* @__PURE__ */ new Set()) : new Set(e.values());
127
127
  } else if (e instanceof Map) {
128
- if (!qe(e)) {
129
- const r = Object.getPrototypeOf(e).constructor;
130
- return new r(e);
128
+ if (!Qe(e)) {
129
+ const i = Object.getPrototypeOf(e).constructor;
130
+ return new i(e);
131
131
  }
132
132
  return new Map(e);
133
- } else if (t?.mark && (n = t.mark(e, K), n !== void 0) && n !== K.mutable) {
134
- if (n === K.immutable)
135
- return Qe(e);
133
+ } else if (t?.mark && (n = t.mark(e, Z), n !== void 0) && n !== Z.mutable) {
134
+ if (n === Z.immutable)
135
+ return lt(e);
136
136
  if (typeof n == "function") {
137
137
  if (t.enablePatches || t.enableAutoFreeze)
138
138
  throw new Error("You can't use mark and patches or auto freeze together.");
@@ -140,274 +140,274 @@ function tt(e, t) {
140
140
  }
141
141
  throw new Error(`Unsupported mark result: ${n}`);
142
142
  } else if (typeof e == "object" && Object.getPrototypeOf(e) === Object.prototype) {
143
- const r = {};
144
- return Object.keys(e).forEach((i) => {
145
- r[i] = e[i];
146
- }), Object.getOwnPropertySymbols(e).forEach((i) => {
147
- et.call(e, i) && (r[i] = e[i]);
148
- }), r;
143
+ const i = {};
144
+ return Object.keys(e).forEach((r) => {
145
+ i[r] = e[r];
146
+ }), Object.getOwnPropertySymbols(e).forEach((r) => {
147
+ ft.call(e, r) && (i[r] = e[r]);
148
+ }), i;
149
149
  } else
150
150
  throw new Error("Please check mark() to ensure that it is a stable marker draftable function.");
151
151
  }
152
- function q(e) {
153
- e.copy || (e.copy = tt(e.original, e.options));
152
+ function J(e) {
153
+ e.copy || (e.copy = pt(e.original, e.options));
154
154
  }
155
- function oe(e) {
156
- if (!Q(e))
157
- return Ie(e);
155
+ function me(e) {
156
+ if (!ce(e))
157
+ return Ce(e);
158
158
  if (Array.isArray(e))
159
- return e.map(oe);
159
+ return e.map(me);
160
160
  if (e instanceof Map) {
161
- const n = Array.from(e.entries()).map(([r, i]) => [
162
- r,
163
- oe(i)
161
+ const n = Array.from(e.entries()).map(([i, r]) => [
162
+ i,
163
+ me(r)
164
164
  ]);
165
- if (!qe(e)) {
166
- const r = Object.getPrototypeOf(e).constructor;
167
- return new r(n);
165
+ if (!Qe(e)) {
166
+ const i = Object.getPrototypeOf(e).constructor;
167
+ return new i(n);
168
168
  }
169
169
  return new Map(n);
170
170
  }
171
171
  if (e instanceof Set) {
172
- const n = Array.from(e).map(oe);
173
- if (!ze(e)) {
174
- const r = Object.getPrototypeOf(e).constructor;
175
- return new r(n);
172
+ const n = Array.from(e).map(me);
173
+ if (!Ze(e)) {
174
+ const i = Object.getPrototypeOf(e).constructor;
175
+ return new i(n);
176
176
  }
177
177
  return new Set(n);
178
178
  }
179
179
  const t = Object.create(Object.getPrototypeOf(e));
180
180
  for (const n in e)
181
- t[n] = oe(e[n]);
181
+ t[n] = me(e[n]);
182
182
  return t;
183
183
  }
184
- function pe(e) {
185
- return ye(e) ? oe(e) : e;
184
+ function Oe(e) {
185
+ return ve(e) ? me(e) : e;
186
186
  }
187
- function W(e) {
187
+ function te(e) {
188
188
  var t;
189
- e.assignedMap = (t = e.assignedMap) !== null && t !== void 0 ? t : /* @__PURE__ */ new Map(), e.operated || (e.operated = !0, e.parent && W(e.parent));
189
+ e.assignedMap = (t = e.assignedMap) !== null && t !== void 0 ? t : /* @__PURE__ */ new Map(), e.operated || (e.operated = !0, e.parent && te(e.parent));
190
190
  }
191
- function nt(e, t) {
192
- const n = le(e);
191
+ function mt(e, t) {
192
+ const n = we(e);
193
193
  if (n === 0)
194
- Reflect.ownKeys(e).forEach((r) => {
195
- t(r, e[r], e);
194
+ Reflect.ownKeys(e).forEach((i) => {
195
+ t(i, e[i], e);
196
196
  });
197
197
  else if (n === 1) {
198
- let r = 0;
199
- for (const i of e)
200
- t(r, i, e), r += 1;
198
+ let i = 0;
199
+ for (const r of e)
200
+ t(i, r, e), i += 1;
201
201
  } else
202
- e.forEach((r, i) => t(i, r, e));
202
+ e.forEach((i, r) => t(r, i, e));
203
203
  }
204
- function Fe(e, t, n) {
205
- if (ye(e) || !Q(e, n) || t.has(e) || Object.isFrozen(e))
204
+ function tt(e, t, n) {
205
+ if (ve(e) || !ce(e, n) || t.has(e) || Object.isFrozen(e))
206
206
  return;
207
- const r = e instanceof Set, i = r ? /* @__PURE__ */ new Map() : void 0;
208
- if (t.add(e), nt(e, (o, f) => {
209
- var s;
210
- if (ye(f)) {
211
- const a = v(f);
212
- q(a);
213
- const c = !((s = a.assignedMap) === null || s === void 0) && s.size || a.operated ? a.copy : a.original;
214
- Te(r ? i : e, o, c);
207
+ const i = e instanceof Set, r = i ? /* @__PURE__ */ new Map() : void 0;
208
+ if (t.add(e), mt(e, (s, a) => {
209
+ var u;
210
+ if (ve(a)) {
211
+ const o = T(a);
212
+ J(o);
213
+ const c = !((u = o.assignedMap) === null || u === void 0) && u.size || o.operated ? o.copy : o.original;
214
+ Le(i ? r : e, s, c);
215
215
  } else
216
- Fe(f, t, n);
217
- }), i) {
218
- const o = e, f = Array.from(o);
219
- o.clear(), f.forEach((s) => {
220
- o.add(i.has(s) ? i.get(s) : s);
216
+ tt(a, t, n);
217
+ }), r) {
218
+ const s = e, a = Array.from(s);
219
+ s.clear(), a.forEach((u) => {
220
+ s.add(r.has(u) ? r.get(u) : u);
221
221
  });
222
222
  }
223
223
  }
224
- function rt(e, t) {
224
+ function yt(e, t) {
225
225
  const n = e.type === 3 ? e.setMap : e.copy;
226
- e.finalities.revoke.length > 1 && e.assignedMap.get(t) && n && Fe(H(n, t), e.finalities.handledSet, e.options);
226
+ e.finalities.revoke.length > 1 && e.assignedMap.get(t) && n && tt(ie(n, t), e.finalities.handledSet, e.options);
227
227
  }
228
- function _e(e) {
228
+ function Me(e) {
229
229
  e.type === 3 && e.copy && (e.copy.clear(), e.setMap.forEach((t) => {
230
- e.copy.add(Ie(t));
230
+ e.copy.add(Ce(t));
231
231
  }));
232
232
  }
233
- function Oe(e, t, n, r) {
233
+ function Te(e, t, n, i) {
234
234
  if (e.operated && e.assignedMap && e.assignedMap.size > 0 && !e.finalized) {
235
- if (n && r) {
236
- const o = Ve(e);
237
- o && t(e, o, n, r);
235
+ if (n && i) {
236
+ const s = et(e);
237
+ s && t(e, s, n, i);
238
238
  }
239
239
  e.finalized = !0;
240
240
  }
241
241
  }
242
- function Re(e, t, n, r) {
243
- const i = v(n);
244
- i && (i.callbacks || (i.callbacks = []), i.callbacks.push((o, f) => {
245
- var s;
246
- const a = e.type === 3 ? e.setMap : e.copy;
247
- if (Z(H(a, t), n)) {
248
- let c = i.original;
249
- i.copy && (c = i.copy), _e(e), Oe(e, r, o, f), e.options.enableAutoFreeze && (e.options.updatedValues = (s = e.options.updatedValues) !== null && s !== void 0 ? s : /* @__PURE__ */ new WeakMap(), e.options.updatedValues.set(c, i.original)), Te(a, t, c);
250
- }
251
- }), e.options.enableAutoFreeze && i.finalities !== e.finalities && (e.options.enableAutoFreeze = !1)), Q(n, e.options) && e.finalities.draft.push(() => {
242
+ function Fe(e, t, n, i) {
243
+ const r = T(n);
244
+ r && (r.callbacks || (r.callbacks = []), r.callbacks.push((s, a) => {
245
+ var u;
252
246
  const o = e.type === 3 ? e.setMap : e.copy;
253
- Z(H(o, t), n) && rt(e, t);
247
+ if (ae(ie(o, t), n)) {
248
+ let c = r.original;
249
+ r.copy && (c = r.copy), Me(e), Te(e, i, s, a), e.options.enableAutoFreeze && (e.options.updatedValues = (u = e.options.updatedValues) !== null && u !== void 0 ? u : /* @__PURE__ */ new WeakMap(), e.options.updatedValues.set(c, r.original)), Le(o, t, c);
250
+ }
251
+ }), e.options.enableAutoFreeze && r.finalities !== e.finalities && (e.options.enableAutoFreeze = !1)), ce(n, e.options) && e.finalities.draft.push(() => {
252
+ const s = e.type === 3 ? e.setMap : e.copy;
253
+ ae(ie(s, t), n) && yt(e, t);
254
254
  });
255
255
  }
256
- function it(e, t, n, r, i) {
257
- let { original: o, assignedMap: f, options: s } = e, a = e.copy;
258
- a.length < o.length && ([o, a] = [a, o], [n, r] = [r, n]);
259
- for (let c = 0; c < o.length; c += 1)
260
- if (f.get(c.toString()) && a[c] !== o[c]) {
261
- const l = t.concat([c]), y = X(l, i);
256
+ function ht(e, t, n, i, r) {
257
+ let { original: s, assignedMap: a, options: u } = e, o = e.copy;
258
+ o.length < s.length && ([s, o] = [o, s], [n, i] = [i, n]);
259
+ for (let c = 0; c < s.length; c += 1)
260
+ if (a.get(c.toString()) && o[c] !== s[c]) {
261
+ const d = t.concat([c]), f = se(d, r);
262
262
  n.push({
263
- op: k.Replace,
264
- path: y,
263
+ op: V.Replace,
264
+ path: f,
265
265
  // If it is a draft, it needs to be deep cloned, and it may also be non-draft.
266
- value: pe(a[c])
267
- }), r.push({
268
- op: k.Replace,
269
- path: y,
266
+ value: Oe(o[c])
267
+ }), i.push({
268
+ op: V.Replace,
269
+ path: f,
270
270
  // If it is a draft, it needs to be deep cloned, and it may also be non-draft.
271
- value: pe(o[c])
271
+ value: Oe(s[c])
272
272
  });
273
273
  }
274
- for (let c = o.length; c < a.length; c += 1) {
275
- const l = t.concat([c]), y = X(l, i);
274
+ for (let c = s.length; c < o.length; c += 1) {
275
+ const d = t.concat([c]), f = se(d, r);
276
276
  n.push({
277
- op: k.Add,
278
- path: y,
277
+ op: V.Add,
278
+ path: f,
279
279
  // If it is a draft, it needs to be deep cloned, and it may also be non-draft.
280
- value: pe(a[c])
280
+ value: Oe(o[c])
281
281
  });
282
282
  }
283
- if (o.length < a.length) {
284
- const { arrayLengthAssignment: c = !0 } = s.enablePatches;
283
+ if (s.length < o.length) {
284
+ const { arrayLengthAssignment: c = !0 } = u.enablePatches;
285
285
  if (c) {
286
- const l = t.concat(["length"]), y = X(l, i);
287
- r.push({
288
- op: k.Replace,
289
- path: y,
290
- value: o.length
286
+ const d = t.concat(["length"]), f = se(d, r);
287
+ i.push({
288
+ op: V.Replace,
289
+ path: f,
290
+ value: s.length
291
291
  });
292
292
  } else
293
- for (let l = a.length; o.length < l; l -= 1) {
294
- const y = t.concat([l - 1]), w = X(y, i);
295
- r.push({
296
- op: k.Remove,
297
- path: w
293
+ for (let d = o.length; s.length < d; d -= 1) {
294
+ const f = t.concat([d - 1]), g = se(f, r);
295
+ i.push({
296
+ op: V.Remove,
297
+ path: g
298
298
  });
299
299
  }
300
300
  }
301
301
  }
302
- function ot({ original: e, copy: t, assignedMap: n }, r, i, o, f) {
303
- n.forEach((s, a) => {
304
- const c = H(e, a), l = pe(H(t, a)), y = s ? ae(e, a) ? k.Replace : k.Add : k.Remove;
305
- if (Z(c, l) && y === k.Replace)
302
+ function bt({ original: e, copy: t, assignedMap: n }, i, r, s, a) {
303
+ n.forEach((u, o) => {
304
+ const c = ie(e, o), d = Oe(ie(t, o)), f = u ? ye(e, o) ? V.Replace : V.Add : V.Remove;
305
+ if (ae(c, d) && f === V.Replace)
306
306
  return;
307
- const w = r.concat(a), S = X(w, f);
308
- i.push(y === k.Remove ? { op: y, path: S } : { op: y, path: S, value: l }), o.push(y === k.Add ? { op: k.Remove, path: S } : y === k.Remove ? { op: k.Add, path: S, value: c } : { op: k.Replace, path: S, value: c });
307
+ const g = i.concat(o), $ = se(g, a);
308
+ r.push(f === V.Remove ? { op: f, path: $ } : { op: f, path: $, value: d }), s.push(f === V.Add ? { op: V.Remove, path: $ } : f === V.Remove ? { op: V.Add, path: $, value: c } : { op: V.Replace, path: $, value: c });
309
309
  });
310
310
  }
311
- function st({ original: e, copy: t }, n, r, i, o) {
312
- let f = 0;
313
- e.forEach((s) => {
314
- if (!t.has(s)) {
315
- const a = n.concat([f]), c = X(a, o);
316
- r.push({
317
- op: k.Remove,
311
+ function wt({ original: e, copy: t }, n, i, r, s) {
312
+ let a = 0;
313
+ e.forEach((u) => {
314
+ if (!t.has(u)) {
315
+ const o = n.concat([a]), c = se(o, s);
316
+ i.push({
317
+ op: V.Remove,
318
318
  path: c,
319
- value: s
320
- }), i.unshift({
321
- op: k.Add,
319
+ value: u
320
+ }), r.unshift({
321
+ op: V.Add,
322
322
  path: c,
323
- value: s
323
+ value: u
324
324
  });
325
325
  }
326
- f += 1;
327
- }), f = 0, t.forEach((s) => {
328
- if (!e.has(s)) {
329
- const a = n.concat([f]), c = X(a, o);
330
- r.push({
331
- op: k.Add,
326
+ a += 1;
327
+ }), a = 0, t.forEach((u) => {
328
+ if (!e.has(u)) {
329
+ const o = n.concat([a]), c = se(o, s);
330
+ i.push({
331
+ op: V.Add,
332
332
  path: c,
333
- value: s
334
- }), i.unshift({
335
- op: k.Remove,
333
+ value: u
334
+ }), r.unshift({
335
+ op: V.Remove,
336
336
  path: c,
337
- value: s
337
+ value: u
338
338
  });
339
339
  }
340
- f += 1;
340
+ a += 1;
341
341
  });
342
342
  }
343
- function ce(e, t, n, r) {
344
- const { pathAsArray: i = !0 } = e.options.enablePatches;
343
+ function be(e, t, n, i) {
344
+ const { pathAsArray: r = !0 } = e.options.enablePatches;
345
345
  switch (e.type) {
346
346
  case 0:
347
347
  case 2:
348
- return ot(e, t, n, r, i);
348
+ return bt(e, t, n, i, r);
349
349
  case 1:
350
- return it(e, t, n, r, i);
350
+ return ht(e, t, n, i, r);
351
351
  case 3:
352
- return st(e, t, n, r, i);
352
+ return wt(e, t, n, i, r);
353
353
  }
354
354
  }
355
- const he = (e, t, n = !1) => {
356
- if (typeof e == "object" && e !== null && (!Q(e, t) || n))
355
+ const _e = (e, t, n = !1) => {
356
+ if (typeof e == "object" && e !== null && (!ce(e, t) || n))
357
357
  throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.");
358
- }, $e = {
358
+ }, je = {
359
359
  get size() {
360
- return F(v(this)).size;
360
+ return W(T(this)).size;
361
361
  },
362
362
  has(e) {
363
- return F(v(this)).has(e);
363
+ return W(T(this)).has(e);
364
364
  },
365
365
  set(e, t) {
366
- const n = v(this), r = F(n);
367
- return (!r.has(e) || !Z(r.get(e), t)) && (q(n), W(n), n.assignedMap.set(e, !0), n.copy.set(e, t), Re(n, e, t, ce)), this;
366
+ const n = T(this), i = W(n);
367
+ return (!i.has(e) || !ae(i.get(e), t)) && (J(n), te(n), n.assignedMap.set(e, !0), n.copy.set(e, t), Fe(n, e, t, be)), this;
368
368
  },
369
369
  delete(e) {
370
370
  if (!this.has(e))
371
371
  return !1;
372
- const t = v(this);
373
- return q(t), W(t), t.original.has(e) ? t.assignedMap.set(e, !1) : t.assignedMap.delete(e), t.copy.delete(e), !0;
372
+ const t = T(this);
373
+ return J(t), te(t), t.original.has(e) ? t.assignedMap.set(e, !1) : t.assignedMap.delete(e), t.copy.delete(e), !0;
374
374
  },
375
375
  clear() {
376
- const e = v(this);
376
+ const e = T(this);
377
377
  if (this.size) {
378
- q(e), W(e), e.assignedMap = /* @__PURE__ */ new Map();
378
+ J(e), te(e), e.assignedMap = /* @__PURE__ */ new Map();
379
379
  for (const [t] of e.original)
380
380
  e.assignedMap.set(t, !1);
381
381
  e.copy.clear();
382
382
  }
383
383
  },
384
384
  forEach(e, t) {
385
- const n = v(this);
386
- F(n).forEach((r, i) => {
387
- e.call(t, this.get(i), i, this);
385
+ const n = T(this);
386
+ W(n).forEach((i, r) => {
387
+ e.call(t, this.get(r), r, this);
388
388
  });
389
389
  },
390
390
  get(e) {
391
391
  var t, n;
392
- const r = v(this), i = F(r).get(e), o = ((n = (t = r.options).mark) === null || n === void 0 ? void 0 : n.call(t, i, K)) === K.mutable;
393
- if (r.options.strict && he(i, r.options, o), o || r.finalized || !Q(i, r.options) || i !== r.original.get(e))
394
- return i;
395
- const f = Ae.createDraft({
396
- original: i,
397
- parentDraft: r,
392
+ const i = T(this), r = W(i).get(e), s = ((n = (t = i.options).mark) === null || n === void 0 ? void 0 : n.call(t, r, Z)) === Z.mutable;
393
+ if (i.options.strict && _e(r, i.options, s), s || i.finalized || !ce(r, i.options) || r !== i.original.get(e))
394
+ return r;
395
+ const a = ke.createDraft({
396
+ original: r,
397
+ parentDraft: i,
398
398
  key: e,
399
- finalities: r.finalities,
400
- options: r.options
399
+ finalities: i.finalities,
400
+ options: i.options
401
401
  });
402
- return q(r), r.copy.set(e, f), f;
402
+ return J(i), i.copy.set(e, a), a;
403
403
  },
404
404
  keys() {
405
- return F(v(this)).keys();
405
+ return W(T(this)).keys();
406
406
  },
407
407
  values() {
408
408
  const e = this.keys();
409
409
  return {
410
- [de]: () => this.values(),
410
+ [$e]: () => this.values(),
411
411
  next: () => {
412
412
  const t = e.next();
413
413
  return t.done ? t : {
@@ -420,7 +420,7 @@ const he = (e, t, n = !1) => {
420
420
  entries() {
421
421
  const e = this.keys();
422
422
  return {
423
- [de]: () => this.entries(),
423
+ [$e]: () => this.entries(),
424
424
  next: () => {
425
425
  const t = e.next();
426
426
  if (t.done)
@@ -433,80 +433,80 @@ const he = (e, t, n = !1) => {
433
433
  }
434
434
  };
435
435
  },
436
- [de]() {
436
+ [$e]() {
437
437
  return this.entries();
438
438
  }
439
- }, at = Reflect.ownKeys($e), xe = (e, t, { isValuesIterator: n }) => () => {
440
- var r, i;
441
- const o = t.next();
442
- if (o.done)
443
- return o;
444
- const f = o.value;
445
- let s = e.setMap.get(f);
446
- const a = v(s), c = ((i = (r = e.options).mark) === null || i === void 0 ? void 0 : i.call(r, s, K)) === K.mutable;
447
- if (e.options.strict && he(f, e.options, c), !c && !a && Q(f, e.options) && !e.finalized && e.original.has(f)) {
448
- const l = Ae.createDraft({
449
- original: f,
439
+ }, gt = Reflect.ownKeys(je), Pe = (e, t, { isValuesIterator: n }) => () => {
440
+ var i, r;
441
+ const s = t.next();
442
+ if (s.done)
443
+ return s;
444
+ const a = s.value;
445
+ let u = e.setMap.get(a);
446
+ const o = T(u), c = ((r = (i = e.options).mark) === null || r === void 0 ? void 0 : r.call(i, u, Z)) === Z.mutable;
447
+ if (e.options.strict && _e(a, e.options, c), !c && !o && ce(a, e.options) && !e.finalized && e.original.has(a)) {
448
+ const d = ke.createDraft({
449
+ original: a,
450
450
  parentDraft: e,
451
- key: f,
451
+ key: a,
452
452
  finalities: e.finalities,
453
453
  options: e.options
454
454
  });
455
- e.setMap.set(f, l), s = l;
456
- } else a && (s = a.proxy);
455
+ e.setMap.set(a, d), u = d;
456
+ } else o && (u = o.proxy);
457
457
  return {
458
458
  done: !1,
459
- value: n ? s : [s, s]
459
+ value: n ? u : [u, u]
460
460
  };
461
- }, be = {
461
+ }, Ae = {
462
462
  get size() {
463
- return v(this).setMap.size;
463
+ return T(this).setMap.size;
464
464
  },
465
465
  has(e) {
466
- const t = v(this);
466
+ const t = T(this);
467
467
  if (t.setMap.has(e))
468
468
  return !0;
469
- q(t);
470
- const n = v(e);
469
+ J(t);
470
+ const n = T(e);
471
471
  return !!(n && t.setMap.has(n.original));
472
472
  },
473
473
  add(e) {
474
- const t = v(this);
475
- return this.has(e) || (q(t), W(t), t.assignedMap.set(e, !0), t.setMap.set(e, e), Re(t, e, e, ce)), this;
474
+ const t = T(this);
475
+ return this.has(e) || (J(t), te(t), t.assignedMap.set(e, !0), t.setMap.set(e, e), Fe(t, e, e, be)), this;
476
476
  },
477
477
  delete(e) {
478
478
  if (!this.has(e))
479
479
  return !1;
480
- const t = v(this);
481
- q(t), W(t);
482
- const n = v(e);
480
+ const t = T(this);
481
+ J(t), te(t);
482
+ const n = T(e);
483
483
  return n && t.setMap.has(n.original) ? (t.assignedMap.set(n.original, !1), t.setMap.delete(n.original)) : (!n && t.setMap.has(e) ? t.assignedMap.set(e, !1) : t.assignedMap.delete(e), t.setMap.delete(e));
484
484
  },
485
485
  clear() {
486
486
  if (!this.size)
487
487
  return;
488
- const e = v(this);
489
- q(e), W(e);
488
+ const e = T(this);
489
+ J(e), te(e);
490
490
  for (const t of e.original)
491
491
  e.assignedMap.set(t, !1);
492
492
  e.setMap.clear();
493
493
  },
494
494
  values() {
495
- const e = v(this);
496
- q(e);
495
+ const e = T(this);
496
+ J(e);
497
497
  const t = e.setMap.keys();
498
498
  return {
499
499
  [Symbol.iterator]: () => this.values(),
500
- next: xe(e, t, { isValuesIterator: !0 })
500
+ next: Pe(e, t, { isValuesIterator: !0 })
501
501
  };
502
502
  },
503
503
  entries() {
504
- const e = v(this);
505
- q(e);
504
+ const e = T(this);
505
+ J(e);
506
506
  const t = e.setMap.keys();
507
507
  return {
508
508
  [Symbol.iterator]: () => this.entries(),
509
- next: xe(e, t, {
509
+ next: Pe(e, t, {
510
510
  isValuesIterator: !1
511
511
  })
512
512
  };
@@ -514,17 +514,17 @@ const he = (e, t, n = !1) => {
514
514
  keys() {
515
515
  return this.values();
516
516
  },
517
- [de]() {
517
+ [$e]() {
518
518
  return this.values();
519
519
  },
520
520
  forEach(e, t) {
521
521
  const n = this.values();
522
- let r = n.next();
523
- for (; !r.done; )
524
- e.call(t, r.value, r.value, this), r = n.next();
522
+ let i = n.next();
523
+ for (; !i.done; )
524
+ e.call(t, i.value, i.value, this), i = n.next();
525
525
  }
526
526
  };
527
- Set.prototype.difference && Object.assign(be, {
527
+ Set.prototype.difference && Object.assign(Ae, {
528
528
  intersection(e) {
529
529
  return Set.prototype.intersection.call(new Set(this.values()), e);
530
530
  },
@@ -547,75 +547,75 @@ Set.prototype.difference && Object.assign(be, {
547
547
  return Set.prototype.isDisjointFrom.call(new Set(this.values()), e);
548
548
  }
549
549
  });
550
- const ut = Reflect.ownKeys(be), Ue = {
550
+ const $t = Reflect.ownKeys(Ae), nt = {
551
551
  get(e, t, n) {
552
- var r, i;
553
- const o = (r = e.copy) === null || r === void 0 ? void 0 : r[t];
554
- if (o && e.finalities.draftsCache.has(o))
555
- return o;
556
- if (t === Pe)
552
+ var i, r;
553
+ const s = (i = e.copy) === null || i === void 0 ? void 0 : i[t];
554
+ if (s && e.finalities.draftsCache.has(s))
555
+ return s;
556
+ if (t === Xe)
557
557
  return e;
558
- let f;
558
+ let a;
559
559
  if (e.options.mark) {
560
560
  const c = t === "size" && (e.original instanceof Map || e.original instanceof Set) ? Reflect.get(e.original, t) : Reflect.get(e.original, t, n);
561
- if (f = e.options.mark(c, K), f === K.mutable)
562
- return e.options.strict && he(c, e.options, !0), c;
561
+ if (a = e.options.mark(c, Z), a === Z.mutable)
562
+ return e.options.strict && _e(c, e.options, !0), c;
563
563
  }
564
- const s = F(e);
565
- if (s instanceof Map && at.includes(t))
566
- return t === "size" ? Object.getOwnPropertyDescriptor($e, "size").get.call(e.proxy) : $e[t].bind(e.proxy);
567
- if (s instanceof Set && ut.includes(t))
568
- return t === "size" ? Object.getOwnPropertyDescriptor(be, "size").get.call(e.proxy) : be[t].bind(e.proxy);
569
- if (!ae(s, t)) {
570
- const c = Me(s, t);
564
+ const u = W(e);
565
+ if (u instanceof Map && gt.includes(t))
566
+ return t === "size" ? Object.getOwnPropertyDescriptor(je, "size").get.call(e.proxy) : je[t].bind(e.proxy);
567
+ if (u instanceof Set && $t.includes(t))
568
+ return t === "size" ? Object.getOwnPropertyDescriptor(Ae, "size").get.call(e.proxy) : Ae[t].bind(e.proxy);
569
+ if (!ye(u, t)) {
570
+ const c = Ue(u, t);
571
571
  return c ? "value" in c ? c.value : (
572
572
  // !case: support for getter
573
- (i = c.get) === null || i === void 0 ? void 0 : i.call(e.proxy)
573
+ (r = c.get) === null || r === void 0 ? void 0 : r.call(e.proxy)
574
574
  ) : void 0;
575
575
  }
576
- const a = s[t];
577
- if (e.options.strict && he(a, e.options), e.finalized || !Q(a, e.options))
578
- return a;
579
- if (a === we(e.original, t)) {
580
- if (q(e), e.copy[t] = Be({
576
+ const o = u[t];
577
+ if (e.options.strict && _e(o, e.options), e.finalized || !ce(o, e.options))
578
+ return o;
579
+ if (o === Se(e.original, t)) {
580
+ if (J(e), e.copy[t] = rt({
581
581
  original: e.original[t],
582
582
  parentDraft: e,
583
583
  key: e.type === 1 ? Number(t) : t,
584
584
  finalities: e.finalities,
585
585
  options: e.options
586
- }), typeof f == "function") {
587
- const c = v(e.copy[t]);
588
- return q(c), W(c), c.copy;
586
+ }), typeof a == "function") {
587
+ const c = T(e.copy[t]);
588
+ return J(c), te(c), c.copy;
589
589
  }
590
590
  return e.copy[t];
591
591
  }
592
- return ye(a) && e.finalities.draftsCache.add(a), a;
592
+ return ve(o) && e.finalities.draftsCache.add(o), o;
593
593
  },
594
594
  set(e, t, n) {
595
- var r;
595
+ var i;
596
596
  if (e.type === 3 || e.type === 2)
597
597
  throw new Error("Map/Set draft does not support any property assignment.");
598
- let i;
599
- if (e.type === 1 && t !== "length" && !(Number.isInteger(i = Number(t)) && i >= 0 && (t === 0 || i === 0 || String(i) === String(t))))
598
+ let r;
599
+ if (e.type === 1 && t !== "length" && !(Number.isInteger(r = Number(t)) && r >= 0 && (t === 0 || r === 0 || String(r) === String(t))))
600
600
  throw new Error("Only supports setting array indices and the 'length' property.");
601
- const o = Me(F(e), t);
602
- if (o?.set)
603
- return o.set.call(e.proxy, n), !0;
604
- const f = we(F(e), t), s = v(f);
605
- return s && Z(s.original, n) ? (e.copy[t] = n, e.assignedMap = (r = e.assignedMap) !== null && r !== void 0 ? r : /* @__PURE__ */ new Map(), e.assignedMap.set(t, !1), !0) : (Z(n, f) && (n !== void 0 || ae(e.original, t)) || (q(e), W(e), ae(e.original, t) && Z(n, e.original[t]) ? e.assignedMap.delete(t) : e.assignedMap.set(t, !0), e.copy[t] = n, Re(e, t, n, ce)), !0);
601
+ const s = Ue(W(e), t);
602
+ if (s?.set)
603
+ return s.set.call(e.proxy, n), !0;
604
+ const a = Se(W(e), t), u = T(a);
605
+ return u && ae(u.original, n) ? (e.copy[t] = n, e.assignedMap = (i = e.assignedMap) !== null && i !== void 0 ? i : /* @__PURE__ */ new Map(), e.assignedMap.set(t, !1), !0) : (ae(n, a) && (n !== void 0 || ye(e.original, t)) || (J(e), te(e), ye(e.original, t) && ae(n, e.original[t]) ? e.assignedMap.delete(t) : e.assignedMap.set(t, !0), e.copy[t] = n, Fe(e, t, n, be)), !0);
606
606
  },
607
607
  has(e, t) {
608
- return t in F(e);
608
+ return t in W(e);
609
609
  },
610
610
  ownKeys(e) {
611
- return Reflect.ownKeys(F(e));
611
+ return Reflect.ownKeys(W(e));
612
612
  },
613
613
  getOwnPropertyDescriptor(e, t) {
614
- const n = F(e), r = Reflect.getOwnPropertyDescriptor(n, t);
615
- return r && {
614
+ const n = W(e), i = Reflect.getOwnPropertyDescriptor(n, t);
615
+ return i && {
616
616
  writable: !0,
617
617
  configurable: e.type !== 1 || t !== "length",
618
- enumerable: r.enumerable,
618
+ enumerable: i.enumerable,
619
619
  value: n[t]
620
620
  };
621
621
  },
@@ -630,83 +630,83 @@ const ut = Reflect.ownKeys(be), Ue = {
630
630
  },
631
631
  deleteProperty(e, t) {
632
632
  var n;
633
- return e.type === 1 ? Ue.set.call(this, e, t, void 0, e.proxy) : (we(e.original, t) !== void 0 || t in e.original ? (q(e), W(e), e.assignedMap.set(t, !1)) : (e.assignedMap = (n = e.assignedMap) !== null && n !== void 0 ? n : /* @__PURE__ */ new Map(), e.assignedMap.delete(t)), e.copy && delete e.copy[t], !0);
633
+ return e.type === 1 ? nt.set.call(this, e, t, void 0, e.proxy) : (Se(e.original, t) !== void 0 || t in e.original ? (J(e), te(e), e.assignedMap.set(t, !1)) : (e.assignedMap = (n = e.assignedMap) !== null && n !== void 0 ? n : /* @__PURE__ */ new Map(), e.assignedMap.delete(t)), e.copy && delete e.copy[t], !0);
634
634
  }
635
635
  };
636
- function Be(e) {
637
- const { original: t, parentDraft: n, key: r, finalities: i, options: o } = e, f = le(t), s = {
638
- type: f,
636
+ function rt(e) {
637
+ const { original: t, parentDraft: n, key: i, finalities: r, options: s } = e, a = we(t), u = {
638
+ type: a,
639
639
  finalized: !1,
640
640
  parent: n,
641
641
  original: t,
642
642
  copy: null,
643
643
  proxy: null,
644
- finalities: i,
645
- options: o,
644
+ finalities: r,
645
+ options: s,
646
646
  // Mapping of draft Set items to their corresponding draft values.
647
- setMap: f === 3 ? new Map(t.entries()) : void 0
647
+ setMap: a === 3 ? new Map(t.entries()) : void 0
648
648
  };
649
- (r || "key" in e) && (s.key = r);
650
- const { proxy: a, revoke: c } = Proxy.revocable(f === 1 ? Object.assign([], s) : s, Ue);
651
- if (i.revoke.push(c), s.proxy = a, n) {
652
- const l = n;
653
- l.finalities.draft.push((y, w) => {
654
- var S, C;
655
- const x = v(a);
656
- let E = l.type === 3 ? l.setMap : l.copy;
657
- const B = H(E, r), V = v(B);
658
- if (V) {
659
- let u = V.original;
660
- V.operated && (u = Ie(B)), _e(V), Oe(V, ce, y, w), l.options.enableAutoFreeze && (l.options.updatedValues = (S = l.options.updatedValues) !== null && S !== void 0 ? S : /* @__PURE__ */ new WeakMap(), l.options.updatedValues.set(u, V.original)), Te(E, r, u);
649
+ (i || "key" in e) && (u.key = i);
650
+ const { proxy: o, revoke: c } = Proxy.revocable(a === 1 ? Object.assign([], u) : u, nt);
651
+ if (r.revoke.push(c), u.proxy = o, n) {
652
+ const d = n;
653
+ d.finalities.draft.push((f, g) => {
654
+ var $, v;
655
+ const j = T(o);
656
+ let P = d.type === 3 ? d.setMap : d.copy;
657
+ const X = ie(P, i), H = T(X);
658
+ if (H) {
659
+ let C = H.original;
660
+ H.operated && (C = Ce(X)), Me(H), Te(H, be, f, g), d.options.enableAutoFreeze && (d.options.updatedValues = ($ = d.options.updatedValues) !== null && $ !== void 0 ? $ : /* @__PURE__ */ new WeakMap(), d.options.updatedValues.set(C, H.original)), Le(P, i, C);
661
661
  }
662
- (C = x.callbacks) === null || C === void 0 || C.forEach((u) => {
663
- u(y, w);
662
+ (v = j.callbacks) === null || v === void 0 || v.forEach((C) => {
663
+ C(f, g);
664
664
  });
665
665
  });
666
666
  } else {
667
- const l = v(a);
668
- l.finalities.draft.push((y, w) => {
669
- _e(l), Oe(l, ce, y, w);
667
+ const d = T(o);
668
+ d.finalities.draft.push((f, g) => {
669
+ Me(d), Te(d, be, f, g);
670
670
  });
671
671
  }
672
- return a;
672
+ return o;
673
673
  }
674
- Ae.createDraft = Be;
674
+ ke.createDraft = rt;
675
675
  Object.prototype.constructor.toString();
676
- const P = [];
676
+ const z = [];
677
677
  for (let e = 0; e < 256; ++e)
678
- P.push((e + 256).toString(16).slice(1));
679
- function ct(e, t = 0) {
680
- return (P[e[t + 0]] + P[e[t + 1]] + P[e[t + 2]] + P[e[t + 3]] + "-" + P[e[t + 4]] + P[e[t + 5]] + "-" + P[e[t + 6]] + P[e[t + 7]] + "-" + P[e[t + 8]] + P[e[t + 9]] + "-" + P[e[t + 10]] + P[e[t + 11]] + P[e[t + 12]] + P[e[t + 13]] + P[e[t + 14]] + P[e[t + 15]]).toLowerCase();
681
- }
682
- let ge;
683
- const lt = new Uint8Array(16);
684
- function ft() {
685
- if (!ge) {
678
+ z.push((e + 256).toString(16).slice(1));
679
+ function Ot(e, t = 0) {
680
+ return (z[e[t + 0]] + z[e[t + 1]] + z[e[t + 2]] + z[e[t + 3]] + "-" + z[e[t + 4]] + z[e[t + 5]] + "-" + z[e[t + 6]] + z[e[t + 7]] + "-" + z[e[t + 8]] + z[e[t + 9]] + "-" + z[e[t + 10]] + z[e[t + 11]] + z[e[t + 12]] + z[e[t + 13]] + z[e[t + 14]] + z[e[t + 15]]).toLowerCase();
681
+ }
682
+ let Ie;
683
+ const Nt = new Uint8Array(16);
684
+ function vt() {
685
+ if (!Ie) {
686
686
  if (typeof crypto > "u" || !crypto.getRandomValues)
687
687
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
688
- ge = crypto.getRandomValues.bind(crypto);
688
+ Ie = crypto.getRandomValues.bind(crypto);
689
689
  }
690
- return ge(lt);
690
+ return Ie(Nt);
691
691
  }
692
- const dt = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), je = { randomUUID: dt };
693
- function pt(e, t, n) {
694
- if (je.randomUUID && !e)
695
- return je.randomUUID();
692
+ const _t = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Be = { randomUUID: _t };
693
+ function At(e, t, n) {
694
+ if (Be.randomUUID && !e)
695
+ return Be.randomUUID();
696
696
  e = e || {};
697
- const r = e.random ?? e.rng?.() ?? ft();
698
- if (r.length < 16)
697
+ const i = e.random ?? e.rng?.() ?? vt();
698
+ if (i.length < 16)
699
699
  throw new Error("Random bytes length must be >= 16");
700
- return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, ct(r);
700
+ return i[6] = i[6] & 15 | 64, i[8] = i[8] & 63 | 128, Ot(i);
701
701
  }
702
- function mt() {
703
- return pt();
702
+ function St() {
703
+ return At();
704
704
  }
705
- function yt(e, t) {
705
+ function It(e, t) {
706
706
  return e.localeCompare(t);
707
707
  }
708
- function ht() {
709
- let e = yt;
708
+ function Mt() {
709
+ let e = It;
710
710
  if (typeof Intl == "object" && Intl.hasOwnProperty("Collator"))
711
711
  try {
712
712
  e = Intl.Collator("en-US").compare;
@@ -714,8 +714,8 @@ function ht() {
714
714
  }
715
715
  return e;
716
716
  }
717
- ht();
718
- function bt() {
717
+ Mt();
718
+ function Tt() {
719
719
  const t = {
720
720
  __etype: 1,
721
721
  __ops: 1,
@@ -729,127 +729,149 @@ function bt() {
729
729
  };
730
730
  return new Set(Object.keys(t));
731
731
  }
732
- const wt = bt();
733
- function ve(e, t, n) {
734
- const r = {
732
+ const jt = Tt();
733
+ function xe(e, t, n) {
734
+ const i = {
735
735
  __etype: e,
736
736
  __ops: n
737
737
  };
738
- return new Proxy(r, {
739
- get: (i, o) => {
740
- if (o === "__ops")
738
+ return new Proxy(i, {
739
+ get: (r, s) => {
740
+ if (s === "__ops")
741
741
  return n;
742
- if (o === "__etype")
742
+ if (s === "__etype")
743
743
  return e;
744
- if (wt.has(o))
745
- return (f, s) => ve(e, t, [
744
+ if (jt.has(s))
745
+ return (a, u) => xe(e, t, [
746
746
  ...n,
747
- s ? [o, e, t, f, s] : [o, e, t, f]
747
+ u ? [s, e, t, a, u] : [s, e, t, a]
748
748
  ]);
749
749
  }
750
750
  });
751
751
  }
752
- function gt(e) {
752
+ function xt(e) {
753
753
  return e.startsWith("lookup__");
754
754
  }
755
- function _t(e) {
756
- const [t, n, ...r] = e.split("__");
757
- return [n, JSON.parse(r.join("__"))];
755
+ function Rt(e) {
756
+ const [t, n, ...i] = e.split("__");
757
+ return [n, JSON.parse(i.join("__"))];
758
758
  }
759
- function Ot(e) {
759
+ function Dt(e) {
760
760
  return new Proxy({
761
761
  __etype: e
762
762
  }, {
763
763
  get(t, n) {
764
764
  if (n === "__etype")
765
765
  return e;
766
- const r = n;
767
- return gt(r) ? ve(e, _t(r), []) : ve(e, r, []);
766
+ const i = n;
767
+ return xt(i) ? xe(e, Rt(i), []) : xe(e, i, []);
768
768
  }
769
769
  });
770
770
  }
771
- function $t() {
771
+ function Et() {
772
772
  return new Proxy({}, {
773
773
  get(e, t) {
774
- return Ot(t);
774
+ return Dt(t);
775
775
  }
776
776
  });
777
777
  }
778
- $t();
779
- const vt = { "unique?": !0, "index?": !0 };
780
- Object.assign(Object.assign({}, vt), { cardinality: "one" });
778
+ Et();
779
+ const kt = { "unique?": !0, "index?": !0 };
780
+ Object.assign(Object.assign({}, kt), { cardinality: "one" });
781
781
  typeof window < "u" && typeof window.localStorage < "u" && (window.localStorage.getItem("devBackend"), window.localStorage.getItem("__instantLogging"), window.localStorage.getItem("__devtoolLocalDash"));
782
- function Nt() {
782
+ function Ct() {
783
783
  var e;
784
784
  return globalThis.__instantDbSchemaHashStore = (e = globalThis.__instantDbSchemaHashStore) !== null && e !== void 0 ? e : /* @__PURE__ */ new WeakMap(), globalThis.__instantDbSchemaHashStore;
785
785
  }
786
- function St() {
786
+ function Lt() {
787
787
  var e;
788
788
  return globalThis.__instantDbStore = (e = globalThis.__instantDbStore) !== null && e !== void 0 ? e : {}, globalThis.__instantDbStore;
789
789
  }
790
- St();
791
- Nt();
792
- const me = /* @__PURE__ */ Object.create(null), ne = (e) => globalThis.process?.env || //@ts-expect-error
793
- globalThis.Deno?.env.toObject() || //@ts-expect-error
794
- globalThis.__env__ || (e ? me : globalThis), re = new Proxy(me, {
790
+ Lt();
791
+ Ct();
792
+ var re = class extends Error {
793
+ constructor(e, t) {
794
+ super(e, t), this.name = "BetterAuthError", this.message = e, this.stack = "";
795
+ }
796
+ };
797
+ const de = ({ usePlural: e, schema: t }) => (i) => {
798
+ if (e && i.charAt(i.length - 1) === "s") {
799
+ const s = i.slice(0, -1);
800
+ let a = t[s] ? s : void 0;
801
+ if (a || (a = Object.entries(t).find(([u, o]) => o.modelName === s)?.[0]), a) return a;
802
+ }
803
+ let r = t[i] ? i : void 0;
804
+ if (r || (r = Object.entries(t).find(([s, a]) => a.modelName === i)?.[0]), !r) throw new re(`Model "${i}" not found in schema`);
805
+ return r;
806
+ }, qe = ({ schema: e, usePlural: t }) => {
807
+ const n = de({
808
+ schema: e,
809
+ usePlural: t
810
+ });
811
+ return ({ field: r, model: s }) => {
812
+ if (r === "id" || r === "_id") return "id";
813
+ const a = n(s);
814
+ let u = e[a]?.fields[r];
815
+ if (!u) {
816
+ const o = Object.entries(e[a].fields).find(([c, d]) => d.fieldName === r);
817
+ o && (u = o[1], r = o[0]);
818
+ }
819
+ if (!u) throw new re(`Field ${r} not found in model ${a}`);
820
+ return r;
821
+ };
822
+ }, Ne = /* @__PURE__ */ Object.create(null), le = (e) => globalThis.process?.env || globalThis.Deno?.env.toObject() || globalThis.__env__ || (e ? Ne : globalThis), fe = new Proxy(Ne, {
795
823
  get(e, t) {
796
- return ne()[t] ?? me[t];
824
+ return le()[t] ?? Ne[t];
797
825
  },
798
826
  has(e, t) {
799
- const n = ne();
800
- return t in n || t in me;
827
+ return t in le() || t in Ne;
801
828
  },
802
829
  set(e, t, n) {
803
- const r = ne(!0);
804
- return r[t] = n, !0;
830
+ const i = le(!0);
831
+ return i[t] = n, !0;
805
832
  },
806
833
  deleteProperty(e, t) {
807
- if (!t)
808
- return !1;
809
- const n = ne(!0);
834
+ if (!t) return !1;
835
+ const n = le(!0);
810
836
  return delete n[t], !0;
811
837
  },
812
838
  ownKeys() {
813
- const e = ne(!0);
839
+ const e = le(!0);
814
840
  return Object.keys(e);
815
841
  }
816
842
  });
817
843
  typeof process < "u" && process.env && process.env.NODE_ENV;
818
- function M(e, t) {
844
+ function L(e, t) {
819
845
  return typeof process < "u" && process.env ? process.env[e] ?? t : typeof Deno < "u" ? Deno.env.get(e) ?? t : typeof Bun < "u" ? Bun.env[e] ?? t : t;
820
846
  }
821
- const ie = 1, L = 4, G = 8, U = 24, ke = {
822
- eterm: L,
823
- cons25: L,
824
- console: L,
825
- cygwin: L,
826
- dtterm: L,
827
- gnome: L,
828
- hurd: L,
829
- jfbterm: L,
830
- konsole: L,
831
- kterm: L,
832
- mlterm: L,
833
- mosh: U,
834
- putty: L,
835
- st: L,
836
- // http://lists.schmorp.de/pipermail/rxvt-unicode/2016q2/002261.html
837
- "rxvt-unicode-24bit": U,
838
- // https://bugs.launchpad.net/terminator/+bug/1030562
839
- terminator: U,
840
- "xterm-kitty": U
841
- }, At = new Map(
842
- Object.entries({
843
- APPVEYOR: G,
844
- BUILDKITE: G,
845
- CIRCLECI: U,
846
- DRONE: G,
847
- GITEA_ACTIONS: U,
848
- GITHUB_ACTIONS: U,
849
- GITLAB_CI: G,
850
- TRAVIS: G
851
- })
852
- ), It = [
847
+ const pe = 1, B = 4, ee = 8, Y = 24, ze = {
848
+ eterm: B,
849
+ cons25: B,
850
+ console: B,
851
+ cygwin: B,
852
+ dtterm: B,
853
+ gnome: B,
854
+ hurd: B,
855
+ jfbterm: B,
856
+ konsole: B,
857
+ kterm: B,
858
+ mlterm: B,
859
+ mosh: Y,
860
+ putty: B,
861
+ st: B,
862
+ "rxvt-unicode-24bit": Y,
863
+ terminator: Y,
864
+ "xterm-kitty": Y
865
+ }, Ft = new Map(Object.entries({
866
+ APPVEYOR: ee,
867
+ BUILDKITE: ee,
868
+ CIRCLECI: Y,
869
+ DRONE: ee,
870
+ GITEA_ACTIONS: Y,
871
+ GITHUB_ACTIONS: Y,
872
+ GITLAB_CI: ee,
873
+ TRAVIS: ee
874
+ })), qt = [
853
875
  /ansi/,
854
876
  /color/,
855
877
  /linux/,
@@ -861,65 +883,47 @@ const ie = 1, L = 4, G = 8, U = 24, ke = {
861
883
  /^vt100/,
862
884
  /^vt220/
863
885
  ];
864
- function Ke() {
865
- if (M("FORCE_COLOR") !== void 0)
866
- switch (M("FORCE_COLOR")) {
867
- case "":
868
- case "1":
869
- case "true":
870
- return L;
871
- case "2":
872
- return G;
873
- case "3":
874
- return U;
875
- default:
876
- return ie;
877
- }
878
- if (M("NODE_DISABLE_COLORS") !== void 0 && M("NODE_DISABLE_COLORS") !== "" || // See https://no-color.org/
879
- M("NO_COLOR") !== void 0 && M("NO_COLOR") !== "" || // The "dumb" special terminal, as defined by terminfo, doesn't support
880
- // ANSI color control codes.
881
- // See https://invisible-island.net/ncurses/terminfo.ti.html#toc-_Specials
882
- M("TERM") === "dumb")
883
- return ie;
884
- if (M("TMUX"))
885
- return U;
886
- if ("TF_BUILD" in re && "AGENT_NAME" in re)
887
- return L;
888
- if ("CI" in re) {
889
- for (const { 0: e, 1: t } of At)
890
- if (e in re)
891
- return t;
892
- return M("CI_NAME") === "codeship" ? G : ie;
886
+ function it() {
887
+ if (L("FORCE_COLOR") !== void 0) switch (L("FORCE_COLOR")) {
888
+ case "":
889
+ case "1":
890
+ case "true":
891
+ return B;
892
+ case "2":
893
+ return ee;
894
+ case "3":
895
+ return Y;
896
+ default:
897
+ return pe;
898
+ }
899
+ if (L("NODE_DISABLE_COLORS") !== void 0 && L("NODE_DISABLE_COLORS") !== "" || L("NO_COLOR") !== void 0 && L("NO_COLOR") !== "" || L("TERM") === "dumb") return pe;
900
+ if (L("TMUX")) return Y;
901
+ if ("TF_BUILD" in fe && "AGENT_NAME" in fe) return B;
902
+ if ("CI" in fe) {
903
+ for (const { 0: e, 1: t } of Ft) if (e in fe) return t;
904
+ return L("CI_NAME") === "codeship" ? ee : pe;
893
905
  }
894
- if ("TEAMCITY_VERSION" in re)
895
- return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(
896
- M("TEAMCITY_VERSION")
897
- ) !== null ? L : ie;
898
- switch (M("TERM_PROGRAM")) {
906
+ if ("TEAMCITY_VERSION" in fe) return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(L("TEAMCITY_VERSION")) !== null ? B : pe;
907
+ switch (L("TERM_PROGRAM")) {
899
908
  case "iTerm.app":
900
- return !M("TERM_PROGRAM_VERSION") || /^[0-2]\./.exec(M("TERM_PROGRAM_VERSION")) !== null ? G : U;
909
+ return !L("TERM_PROGRAM_VERSION") || /^[0-2]\./.exec(L("TERM_PROGRAM_VERSION")) !== null ? ee : Y;
901
910
  case "HyperTerm":
902
911
  case "MacTerm":
903
- return U;
912
+ return Y;
904
913
  case "Apple_Terminal":
905
- return G;
914
+ return ee;
906
915
  }
907
- if (M("COLORTERM") === "truecolor" || M("COLORTERM") === "24bit")
908
- return U;
909
- if (M("TERM")) {
910
- if (/truecolor/.exec(M("TERM")) !== null)
911
- return U;
912
- if (/^xterm-256/.exec(M("TERM")) !== null)
913
- return G;
914
- const e = M("TERM").toLowerCase();
915
- if (ke[e])
916
- return ke[e];
917
- if (It.some((t) => t.exec(e) !== null))
918
- return L;
916
+ if (L("COLORTERM") === "truecolor" || L("COLORTERM") === "24bit") return Y;
917
+ if (L("TERM")) {
918
+ if (/truecolor/.exec(L("TERM")) !== null) return Y;
919
+ if (/^xterm-256/.exec(L("TERM")) !== null) return ee;
920
+ const e = L("TERM").toLowerCase();
921
+ if (ze[e]) return ze[e];
922
+ if (qt.some((t) => t.exec(e) !== null)) return B;
919
923
  }
920
- return M("COLORTERM") ? L : ie;
924
+ return L("COLORTERM") ? B : pe;
921
925
  }
922
- const D = {
926
+ const U = {
923
927
  reset: "\x1B[0m",
924
928
  bright: "\x1B[1m",
925
929
  dim: "\x1B[2m",
@@ -933,144 +937,297 @@ const D = {
933
937
  bg: {
934
938
  black: "\x1B[40m"
935
939
  }
936
- }, Ne = ["info", "success", "warn", "error", "debug"];
937
- function Tt(e, t) {
938
- return Ne.indexOf(t) <= Ne.indexOf(e);
939
- }
940
- const Rt = {
941
- info: D.fg.blue,
942
- success: D.fg.green,
943
- warn: D.fg.yellow,
944
- error: D.fg.red,
945
- debug: D.fg.magenta
946
- }, Et = (e, t, n) => {
947
- const r = (/* @__PURE__ */ new Date()).toISOString();
948
- return n ? `${D.dim}${r}${D.reset} ${Rt[e]}${e.toUpperCase()}${D.reset} ${D.bright}[Better Auth]:${D.reset} ${t}` : `${r} ${e.toUpperCase()} [Better Auth]: ${t}`;
949
- }, Mt = (e) => {
950
- const t = "error", n = Ke() !== 1, r = (o, f, s = []) => {
951
- if (!Tt(t, o))
952
- return;
953
- const a = Et(o, f, n);
954
- {
955
- o === "error" ? console.error(a, ...s) : o === "warn" ? console.warn(a, ...s) : console.log(a, ...s);
940
+ }, Re = [
941
+ "debug",
942
+ "info",
943
+ "success",
944
+ "warn",
945
+ "error"
946
+ ];
947
+ function Vt(e, t) {
948
+ return Re.indexOf(t) >= Re.indexOf(e);
949
+ }
950
+ const Ut = {
951
+ info: U.fg.blue,
952
+ success: U.fg.green,
953
+ warn: U.fg.yellow,
954
+ error: U.fg.red,
955
+ debug: U.fg.magenta
956
+ }, Pt = (e, t, n) => {
957
+ const i = (/* @__PURE__ */ new Date()).toISOString();
958
+ return n ? `${U.dim}${i}${U.reset} ${Ut[e]}${e.toUpperCase()}${U.reset} ${U.bright}[Better Auth]:${U.reset} ${t}` : `${i} ${e.toUpperCase()} [Better Auth]: ${t}`;
959
+ }, De = (e) => {
960
+ const t = e?.disabled !== !0, n = e?.level ?? "warn", i = e?.disableColors !== void 0 ? !e.disableColors : it() !== 1, r = (s, a, u = []) => {
961
+ if (!t || !Vt(n, s)) return;
962
+ const o = Pt(s, a, i);
963
+ if (!e || typeof e.log != "function") {
964
+ s === "error" ? console.error(o, ...u) : s === "warn" ? console.warn(o, ...u) : console.log(o, ...u);
956
965
  return;
957
966
  }
967
+ e.log(s === "success" ? "info" : s, a, ...u);
958
968
  };
959
969
  return {
960
- ...Object.fromEntries(
961
- Ne.map((o) => [
962
- o,
963
- (...[f, ...s]) => r(o, f, s)
964
- ])
965
- ),
970
+ ...Object.fromEntries(Re.map((s) => [s, (...[a, ...u]) => r(s, a, u)])),
966
971
  get level() {
967
- return t;
972
+ return n;
968
973
  }
969
974
  };
970
- }, Y = Mt();
971
- function xt(e) {
972
- function t(n, r) {
973
- if (typeof r == "string" && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/.test(r)) {
974
- const o = new Date(r);
975
- if (!isNaN(o.getTime()))
976
- return o;
977
- }
978
- return r;
979
- }
980
- try {
981
- return typeof e != "string" ? e : JSON.parse(e, t);
982
- } catch (n) {
983
- return Y.error("Error parsing JSON", { error: n }), null;
975
+ }, ot = De();
976
+ function Ke(e) {
977
+ switch (e) {
978
+ case "a-z":
979
+ return "abcdefghijklmnopqrstuvwxyz";
980
+ case "A-Z":
981
+ return "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
982
+ case "0-9":
983
+ return "0123456789";
984
+ case "-_":
985
+ return "-_";
986
+ default:
987
+ throw new Error(`Unsupported alphabet: ${e}`);
984
988
  }
985
989
  }
986
- const De = (e) => {
987
- const t = (e.plugins ?? []).reduce(
988
- (c, l) => {
989
- const y = l.schema;
990
- if (!y) return c;
991
- for (const [w, S] of Object.entries(y))
992
- c[w] = {
993
- fields: {
994
- ...c[w]?.fields,
995
- ...S.fields
996
- },
997
- modelName: S.modelName || w
998
- };
999
- return c;
1000
- },
1001
- {}
1002
- ), n = e.rateLimit?.storage === "database", r = {
1003
- rateLimit: {
1004
- modelName: e.rateLimit?.modelName || "rateLimit",
1005
- fields: {
1006
- key: {
1007
- type: "string",
1008
- fieldName: e.rateLimit?.fields?.key || "key"
1009
- },
1010
- count: {
1011
- type: "number",
1012
- fieldName: e.rateLimit?.fields?.count || "count"
990
+ function Bt(...e) {
991
+ const t = e.map(Ke).join("");
992
+ if (t.length === 0)
993
+ throw new Error(
994
+ "No valid characters provided for random string generation."
995
+ );
996
+ const n = t.length;
997
+ return (i, ...r) => {
998
+ if (i <= 0)
999
+ throw new Error("Length must be a positive integer.");
1000
+ let s = t, a = n;
1001
+ r.length > 0 && (s = r.map(Ke).join(""), a = s.length);
1002
+ const u = Math.floor(256 / a) * a, o = new Uint8Array(i * 2), c = o.length;
1003
+ let d = "", f = c, g;
1004
+ for (; d.length < i; )
1005
+ f >= c && (crypto.getRandomValues(o), f = 0), g = o[f++], g < u && (d += s[g % a]);
1006
+ return d;
1007
+ };
1008
+ }
1009
+ const zt = (e) => Bt("a-z", "A-Z", "0-9")(32), st = ({ usePlural: e, schema: t, disableIdGeneration: n, options: i, customIdGenerator: r, supportsUUIDs: s }) => {
1010
+ const a = de({
1011
+ usePlural: e,
1012
+ schema: t
1013
+ });
1014
+ return ({ customModelName: o, forceAllowId: c }) => {
1015
+ const d = i.advanced?.database?.generateId === "serial", f = i.advanced?.database?.generateId === "uuid", g = n || d && !c ? !1 : f ? !s : !0, $ = a(o ?? "id");
1016
+ return {
1017
+ type: d ? "number" : "string",
1018
+ required: !!g,
1019
+ ...g ? { defaultValue() {
1020
+ if (n) return;
1021
+ const v = i.advanced?.database?.generateId;
1022
+ if (!(v === !1 || v === "serial"))
1023
+ return typeof v == "function" ? v({ model: $ }) : v === "uuid" ? crypto.randomUUID() : r ? r({ model: $ }) : zt();
1024
+ } } : {},
1025
+ transform: {
1026
+ input: (v) => {
1027
+ if (v) {
1028
+ if (d) {
1029
+ const j = Number(v);
1030
+ return isNaN(j) ? void 0 : j;
1031
+ }
1032
+ if (f) {
1033
+ if (g && !c) return v;
1034
+ if (n) return;
1035
+ if (c && typeof v == "string") {
1036
+ if (/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(v)) return v;
1037
+ {
1038
+ const j = (/* @__PURE__ */ new Error()).stack?.split(`
1039
+ `).filter((P, X) => X !== 1).join(`
1040
+ `).replace("Error:", "");
1041
+ ot.warn("[Adapter Factory] - Invalid UUID value for field `id` provided when `forceAllowId` is true. Generating a new UUID.", j);
1042
+ }
1043
+ }
1044
+ return s ? void 0 : typeof v != "string" && !s ? crypto.randomUUID() : void 0;
1045
+ }
1046
+ return v;
1047
+ }
1013
1048
  },
1014
- lastRequest: {
1015
- type: "number",
1016
- bigint: !0,
1017
- fieldName: e.rateLimit?.fields?.lastRequest || "lastRequest"
1049
+ output: (v) => {
1050
+ if (v)
1051
+ return String(v);
1018
1052
  }
1019
1053
  }
1020
- }
1021
- }, { user: i, session: o, account: f, ...s } = t, a = {
1022
- session: {
1023
- modelName: e.session?.modelName || "session",
1054
+ };
1055
+ };
1056
+ }, Kt = ({ usePlural: e, schema: t, options: n, customIdGenerator: i, disableIdGeneration: r }) => {
1057
+ const s = de({
1058
+ usePlural: e,
1059
+ schema: t
1060
+ }), a = qe({
1061
+ usePlural: e,
1062
+ schema: t
1063
+ }), u = st({
1064
+ usePlural: e,
1065
+ schema: t,
1066
+ options: n,
1067
+ customIdGenerator: i,
1068
+ disableIdGeneration: r
1069
+ });
1070
+ return ({ model: c, field: d }) => {
1071
+ const f = s(c), g = a({
1072
+ field: d,
1073
+ model: f
1074
+ }), $ = t[f].fields;
1075
+ $.id = u({ customModelName: f });
1076
+ const v = $[g];
1077
+ if (!v) throw new re(`Field ${d} not found in model ${c}`);
1078
+ return v;
1079
+ };
1080
+ }, Gt = ({ schema: e, usePlural: t }) => {
1081
+ const n = de({
1082
+ schema: e,
1083
+ usePlural: t
1084
+ }), i = qe({
1085
+ schema: e,
1086
+ usePlural: t
1087
+ });
1088
+ function r({ model: s, field: a }) {
1089
+ const u = n(s), o = i({
1090
+ model: u,
1091
+ field: a
1092
+ });
1093
+ return e[u]?.fields[o]?.fieldName || o;
1094
+ }
1095
+ return r;
1096
+ }, Jt = ({ usePlural: e, schema: t }) => {
1097
+ const n = de({
1098
+ schema: t,
1099
+ usePlural: e
1100
+ });
1101
+ return (r) => {
1102
+ const s = n(r);
1103
+ return t && t[s] && t[s].modelName !== r ? e ? `${t[s].modelName}s` : t[s].modelName : e ? `${r}s` : r;
1104
+ };
1105
+ };
1106
+ function Ht(e, t, n) {
1107
+ return n === "update" ? e === void 0 && t.onUpdate !== void 0 ? typeof t.onUpdate == "function" ? t.onUpdate() : t.onUpdate : e : n === "create" && (e === void 0 || t.required === !0 && e === null) && t.defaultValue !== void 0 ? typeof t.defaultValue == "function" ? t.defaultValue() : t.defaultValue : e;
1108
+ }
1109
+ const Ge = (e) => {
1110
+ const t = (e.plugins ?? []).reduce((f, g) => {
1111
+ const $ = g.schema;
1112
+ if (!$) return f;
1113
+ for (const [v, j] of Object.entries($)) f[v] = {
1024
1114
  fields: {
1025
- expiresAt: {
1026
- type: "date",
1027
- required: !0,
1028
- fieldName: e.session?.fields?.expiresAt || "expiresAt"
1029
- },
1030
- token: {
1031
- type: "string",
1032
- required: !0,
1033
- fieldName: e.session?.fields?.token || "token",
1034
- unique: !0
1035
- },
1036
- createdAt: {
1037
- type: "date",
1038
- required: !0,
1039
- fieldName: e.session?.fields?.createdAt || "createdAt",
1040
- defaultValue: () => /* @__PURE__ */ new Date()
1041
- },
1042
- updatedAt: {
1043
- type: "date",
1044
- required: !0,
1045
- fieldName: e.session?.fields?.updatedAt || "updatedAt",
1046
- onUpdate: () => /* @__PURE__ */ new Date()
1047
- },
1048
- ipAddress: {
1049
- type: "string",
1050
- required: !1,
1051
- fieldName: e.session?.fields?.ipAddress || "ipAddress"
1052
- },
1053
- userAgent: {
1054
- type: "string",
1055
- required: !1,
1056
- fieldName: e.session?.fields?.userAgent || "userAgent"
1057
- },
1058
- userId: {
1059
- type: "string",
1060
- fieldName: e.session?.fields?.userId || "userId",
1061
- references: {
1062
- model: e.user?.modelName || "user",
1063
- field: "id",
1064
- onDelete: "cascade"
1065
- },
1066
- required: !0
1067
- },
1068
- ...o?.fields,
1069
- ...e.session?.additionalFields
1115
+ ...f[v]?.fields,
1116
+ ...j.fields
1117
+ },
1118
+ modelName: j.modelName || v
1119
+ };
1120
+ return f;
1121
+ }, {}), n = e.rateLimit?.storage === "database", i = { rateLimit: {
1122
+ modelName: e.rateLimit?.modelName || "rateLimit",
1123
+ fields: {
1124
+ key: {
1125
+ type: "string",
1126
+ unique: !0,
1127
+ required: !0,
1128
+ fieldName: e.rateLimit?.fields?.key || "key"
1129
+ },
1130
+ count: {
1131
+ type: "number",
1132
+ required: !0,
1133
+ fieldName: e.rateLimit?.fields?.count || "count"
1070
1134
  },
1071
- order: 2
1135
+ lastRequest: {
1136
+ type: "number",
1137
+ bigint: !0,
1138
+ required: !0,
1139
+ fieldName: e.rateLimit?.fields?.lastRequest || "lastRequest",
1140
+ defaultValue: () => Date.now()
1141
+ }
1072
1142
  }
1073
- };
1143
+ } }, { user: r, session: s, account: a, verification: u, ...o } = t, c = { verification: {
1144
+ modelName: e.verification?.modelName || "verification",
1145
+ fields: {
1146
+ identifier: {
1147
+ type: "string",
1148
+ required: !0,
1149
+ fieldName: e.verification?.fields?.identifier || "identifier",
1150
+ index: !0
1151
+ },
1152
+ value: {
1153
+ type: "string",
1154
+ required: !0,
1155
+ fieldName: e.verification?.fields?.value || "value"
1156
+ },
1157
+ expiresAt: {
1158
+ type: "date",
1159
+ required: !0,
1160
+ fieldName: e.verification?.fields?.expiresAt || "expiresAt"
1161
+ },
1162
+ createdAt: {
1163
+ type: "date",
1164
+ required: !0,
1165
+ defaultValue: () => /* @__PURE__ */ new Date(),
1166
+ fieldName: e.verification?.fields?.createdAt || "createdAt"
1167
+ },
1168
+ updatedAt: {
1169
+ type: "date",
1170
+ required: !0,
1171
+ defaultValue: () => /* @__PURE__ */ new Date(),
1172
+ onUpdate: () => /* @__PURE__ */ new Date(),
1173
+ fieldName: e.verification?.fields?.updatedAt || "updatedAt"
1174
+ },
1175
+ ...u?.fields,
1176
+ ...e.verification?.additionalFields
1177
+ },
1178
+ order: 4
1179
+ } }, d = { session: {
1180
+ modelName: e.session?.modelName || "session",
1181
+ fields: {
1182
+ expiresAt: {
1183
+ type: "date",
1184
+ required: !0,
1185
+ fieldName: e.session?.fields?.expiresAt || "expiresAt"
1186
+ },
1187
+ token: {
1188
+ type: "string",
1189
+ required: !0,
1190
+ fieldName: e.session?.fields?.token || "token",
1191
+ unique: !0
1192
+ },
1193
+ createdAt: {
1194
+ type: "date",
1195
+ required: !0,
1196
+ fieldName: e.session?.fields?.createdAt || "createdAt",
1197
+ defaultValue: () => /* @__PURE__ */ new Date()
1198
+ },
1199
+ updatedAt: {
1200
+ type: "date",
1201
+ required: !0,
1202
+ fieldName: e.session?.fields?.updatedAt || "updatedAt",
1203
+ onUpdate: () => /* @__PURE__ */ new Date()
1204
+ },
1205
+ ipAddress: {
1206
+ type: "string",
1207
+ required: !1,
1208
+ fieldName: e.session?.fields?.ipAddress || "ipAddress"
1209
+ },
1210
+ userAgent: {
1211
+ type: "string",
1212
+ required: !1,
1213
+ fieldName: e.session?.fields?.userAgent || "userAgent"
1214
+ },
1215
+ userId: {
1216
+ type: "string",
1217
+ fieldName: e.session?.fields?.userId || "userId",
1218
+ references: {
1219
+ model: e.user?.modelName || "user",
1220
+ field: "id",
1221
+ onDelete: "cascade"
1222
+ },
1223
+ required: !0,
1224
+ index: !0
1225
+ },
1226
+ ...s?.fields,
1227
+ ...e.session?.additionalFields
1228
+ },
1229
+ order: 2
1230
+ } };
1074
1231
  return {
1075
1232
  user: {
1076
1233
  modelName: e.user?.modelName || "user",
@@ -1113,13 +1270,12 @@ const De = (e) => {
1113
1270
  required: !0,
1114
1271
  fieldName: e.user?.fields?.updatedAt || "updatedAt"
1115
1272
  },
1116
- ...i?.fields,
1273
+ ...r?.fields,
1117
1274
  ...e.user?.additionalFields
1118
1275
  },
1119
1276
  order: 1
1120
1277
  },
1121
- //only add session table if it's not stored in secondary storage
1122
- ...!e.secondaryStorage || e.session?.storeSessionInDatabase ? a : {},
1278
+ ...!e.secondaryStorage || e.session?.storeSessionInDatabase ? d : {},
1123
1279
  account: {
1124
1280
  modelName: e.account?.modelName || "account",
1125
1281
  fields: {
@@ -1141,31 +1297,37 @@ const De = (e) => {
1141
1297
  onDelete: "cascade"
1142
1298
  },
1143
1299
  required: !0,
1144
- fieldName: e.account?.fields?.userId || "userId"
1300
+ fieldName: e.account?.fields?.userId || "userId",
1301
+ index: !0
1145
1302
  },
1146
1303
  accessToken: {
1147
1304
  type: "string",
1148
1305
  required: !1,
1306
+ returned: !1,
1149
1307
  fieldName: e.account?.fields?.accessToken || "accessToken"
1150
1308
  },
1151
1309
  refreshToken: {
1152
1310
  type: "string",
1153
1311
  required: !1,
1312
+ returned: !1,
1154
1313
  fieldName: e.account?.fields?.refreshToken || "refreshToken"
1155
1314
  },
1156
1315
  idToken: {
1157
1316
  type: "string",
1158
1317
  required: !1,
1318
+ returned: !1,
1159
1319
  fieldName: e.account?.fields?.idToken || "idToken"
1160
1320
  },
1161
1321
  accessTokenExpiresAt: {
1162
1322
  type: "date",
1163
1323
  required: !1,
1324
+ returned: !1,
1164
1325
  fieldName: e.account?.fields?.accessTokenExpiresAt || "accessTokenExpiresAt"
1165
1326
  },
1166
1327
  refreshTokenExpiresAt: {
1167
1328
  type: "date",
1168
1329
  required: !1,
1330
+ returned: !1,
1169
1331
  fieldName: e.account?.fields?.refreshTokenExpiresAt || "refreshTokenExpiresAt"
1170
1332
  },
1171
1333
  scope: {
@@ -1176,6 +1338,7 @@ const De = (e) => {
1176
1338
  password: {
1177
1339
  type: "string",
1178
1340
  required: !1,
1341
+ returned: !1,
1179
1342
  fieldName: e.account?.fields?.password || "password"
1180
1343
  },
1181
1344
  createdAt: {
@@ -1190,1186 +1353,695 @@ const De = (e) => {
1190
1353
  fieldName: e.account?.fields?.updatedAt || "updatedAt",
1191
1354
  onUpdate: () => /* @__PURE__ */ new Date()
1192
1355
  },
1193
- ...f?.fields,
1356
+ ...a?.fields,
1194
1357
  ...e.account?.additionalFields
1195
1358
  },
1196
1359
  order: 3
1197
1360
  },
1198
- verification: {
1199
- modelName: e.verification?.modelName || "verification",
1200
- fields: {
1201
- identifier: {
1202
- type: "string",
1203
- required: !0,
1204
- fieldName: e.verification?.fields?.identifier || "identifier"
1205
- },
1206
- value: {
1207
- type: "string",
1208
- required: !0,
1209
- fieldName: e.verification?.fields?.value || "value"
1210
- },
1211
- expiresAt: {
1212
- type: "date",
1213
- required: !0,
1214
- fieldName: e.verification?.fields?.expiresAt || "expiresAt"
1215
- },
1216
- createdAt: {
1217
- type: "date",
1218
- required: !0,
1219
- defaultValue: () => /* @__PURE__ */ new Date(),
1220
- fieldName: e.verification?.fields?.createdAt || "createdAt"
1221
- },
1222
- updatedAt: {
1223
- type: "date",
1224
- required: !0,
1225
- defaultValue: () => /* @__PURE__ */ new Date(),
1226
- onUpdate: () => /* @__PURE__ */ new Date(),
1227
- fieldName: e.verification?.fields?.updatedAt || "updatedAt"
1228
- }
1229
- },
1230
- order: 4
1231
- },
1232
- ...s,
1233
- ...n ? r : {}
1361
+ ...!e.secondaryStorage || e.verification?.storeInDatabase ? c : {},
1362
+ ...o,
1363
+ ...n ? i : {}
1234
1364
  };
1235
- };
1236
- function Le(e) {
1237
- switch (e) {
1238
- case "a-z":
1239
- return "abcdefghijklmnopqrstuvwxyz";
1240
- case "A-Z":
1241
- return "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1242
- case "0-9":
1243
- return "0123456789";
1244
- case "-_":
1245
- return "-_";
1246
- default:
1247
- throw new Error(`Unsupported alphabet: ${e}`);
1365
+ }, Wt = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;
1366
+ function at(e) {
1367
+ if (typeof e == "string" && Wt.test(e)) {
1368
+ const t = new Date(e);
1369
+ if (!isNaN(t.getTime())) return t;
1248
1370
  }
1249
- }
1250
- function Ge(...e) {
1251
- const t = e.map(Le).join("");
1252
- if (t.length === 0)
1253
- throw new Error(
1254
- "No valid characters provided for random string generation."
1255
- );
1256
- const n = t.length;
1257
- return (r, ...i) => {
1258
- if (r <= 0)
1259
- throw new Error("Length must be a positive integer.");
1260
- let o = t, f = n;
1261
- i.length > 0 && (o = i.map(Le).join(""), f = o.length);
1262
- const s = Math.floor(256 / f) * f, a = new Uint8Array(r * 2), c = a.length;
1263
- let l = "", y = c, w;
1264
- for (; l.length < r; )
1265
- y >= c && (crypto.getRandomValues(a), y = 0), w = a[y++], w < s && (l += o[w % f]);
1266
- return l;
1267
- };
1268
- }
1269
- const jt = (e) => Ge("a-z", "A-Z", "0-9")(32);
1270
- var kt = Object.defineProperty, Dt = (e, t) => {
1271
- for (var n in t)
1272
- kt(e, n, { get: t[n], enumerable: !0 });
1273
- }, Lt = {};
1274
- Dt(Lt, {
1275
- BIGINT_FORMAT_RANGES: () => fn,
1276
- Class: () => Sn,
1277
- NUMBER_FORMAT_RANGES: () => ln,
1278
- aborted: () => wn,
1279
- allowsEval: () => en,
1280
- assert: () => Vt,
1281
- assertEqual: () => Ct,
1282
- assertIs: () => zt,
1283
- assertNever: () => qt,
1284
- assertNotEqual: () => Pt,
1285
- assignProp: () => Ee,
1286
- cached: () => We,
1287
- captureStackTrace: () => Qt,
1288
- cleanEnum: () => Nn,
1289
- cleanRegex: () => Gt,
1290
- clone: () => ee,
1291
- createTransparentProxy: () => un,
1292
- defineLazy: () => Ht,
1293
- esc: () => Zt,
1294
- escapeRegex: () => sn,
1295
- extend: () => mn,
1296
- finalizeIssue: () => _n,
1297
- floatSafeRemainder: () => Wt,
1298
- getElementAtPath: () => Jt,
1299
- getEnumValues: () => Ft,
1300
- getLengthableOrigin: () => $n,
1301
- getParsedType: () => nn,
1302
- getSizableOrigin: () => On,
1303
- isObject: () => Se,
1304
- isPlainObject: () => He,
1305
- issue: () => vn,
1306
- joinValues: () => Ut,
1307
- jsonStringifyReplacer: () => Bt,
1308
- merge: () => yn,
1309
- normalizeParams: () => an,
1310
- nullish: () => Kt,
1311
- numKeys: () => tn,
1312
- omit: () => pn,
1313
- optionalKeys: () => cn,
1314
- partial: () => hn,
1315
- pick: () => dn,
1316
- prefixIssues: () => gn,
1317
- primitiveTypes: () => on,
1318
- promiseAllObject: () => Yt,
1319
- propertyKeyTypes: () => rn,
1320
- randomString: () => Xt,
1321
- required: () => bn,
1322
- stringifyPrimitive: () => Je,
1323
- unwrapMessage: () => se
1324
- });
1325
- function Ct(e) {
1326
1371
  return e;
1327
1372
  }
1328
- function Pt(e) {
1329
- return e;
1330
- }
1331
- function zt(e) {
1332
- }
1333
- function qt(e) {
1334
- throw new Error();
1335
- }
1336
- function Vt(e) {
1337
- }
1338
- function Ft(e) {
1339
- const t = Object.values(e).filter((r) => typeof r == "number");
1340
- return Object.entries(e).filter(([r, i]) => t.indexOf(+r) === -1).map(([r, i]) => i);
1341
- }
1342
- function Ut(e, t = "|") {
1343
- return e.map((n) => Je(n)).join(t);
1344
- }
1345
- function Bt(e, t) {
1346
- return typeof t == "bigint" ? t.toString() : t;
1347
- }
1348
- function We(e) {
1349
- return {
1350
- get value() {
1351
- {
1352
- const t = e();
1353
- return Object.defineProperty(this, "value", { value: t }), t;
1354
- }
1355
- }
1356
- };
1357
- }
1358
- function Kt(e) {
1359
- return e == null;
1360
- }
1361
- function Gt(e) {
1362
- const t = e.startsWith("^") ? 1 : 0, n = e.endsWith("$") ? e.length - 1 : e.length;
1363
- return e.slice(t, n);
1364
- }
1365
- function Wt(e, t) {
1366
- const n = (e.toString().split(".")[1] || "").length, r = (t.toString().split(".")[1] || "").length, i = n > r ? n : r, o = Number.parseInt(e.toFixed(i).replace(".", "")), f = Number.parseInt(t.toFixed(i).replace(".", ""));
1367
- return o % f / 10 ** i;
1368
- }
1369
- function Ht(e, t, n) {
1370
- Object.defineProperty(e, t, {
1371
- get() {
1372
- {
1373
- const r = n();
1374
- return e[t] = r, r;
1375
- }
1376
- },
1377
- set(r) {
1378
- Object.defineProperty(e, t, {
1379
- value: r
1380
- // configurable: true,
1381
- });
1382
- },
1383
- configurable: !0
1384
- });
1385
- }
1386
- function Ee(e, t, n) {
1387
- Object.defineProperty(e, t, {
1388
- value: n,
1389
- writable: !0,
1390
- enumerable: !0,
1391
- configurable: !0
1392
- });
1393
- }
1394
- function Jt(e, t) {
1395
- return t ? t.reduce((n, r) => n?.[r], e) : e;
1396
- }
1397
- function Yt(e) {
1398
- const t = Object.keys(e), n = t.map((r) => e[r]);
1399
- return Promise.all(n).then((r) => {
1400
- const i = {};
1401
- for (let o = 0; o < t.length; o++)
1402
- i[t[o]] = r[o];
1403
- return i;
1404
- });
1405
- }
1406
- function Xt(e = 10) {
1407
- const t = "abcdefghijklmnopqrstuvwxyz";
1408
- let n = "";
1409
- for (let r = 0; r < e; r++)
1410
- n += t[Math.floor(Math.random() * t.length)];
1411
- return n;
1412
- }
1413
- function Zt(e) {
1414
- return JSON.stringify(e);
1415
- }
1416
- var Qt = Error.captureStackTrace ? Error.captureStackTrace : (...e) => {
1417
- };
1418
- function Se(e) {
1419
- return typeof e == "object" && e !== null && !Array.isArray(e);
1420
- }
1421
- var en = We(() => {
1422
- if (typeof navigator < "u" && navigator?.userAgent?.includes("Cloudflare"))
1423
- return !1;
1424
- try {
1425
- const e = Function;
1426
- return new e(""), !0;
1427
- } catch {
1428
- return !1;
1429
- }
1430
- });
1431
- function He(e) {
1432
- if (Se(e) === !1)
1433
- return !1;
1434
- const t = e.constructor;
1435
- if (t === void 0)
1436
- return !0;
1437
- const n = t.prototype;
1438
- return !(Se(n) === !1 || Object.prototype.hasOwnProperty.call(n, "isPrototypeOf") === !1);
1439
- }
1440
- function tn(e) {
1441
- let t = 0;
1442
- for (const n in e)
1443
- Object.prototype.hasOwnProperty.call(e, n) && t++;
1444
- return t;
1445
- }
1446
- var nn = (e) => {
1447
- const t = typeof e;
1448
- switch (t) {
1449
- case "undefined":
1450
- return "undefined";
1451
- case "string":
1452
- return "string";
1453
- case "number":
1454
- return Number.isNaN(e) ? "nan" : "number";
1455
- case "boolean":
1456
- return "boolean";
1457
- case "function":
1458
- return "function";
1459
- case "bigint":
1460
- return "bigint";
1461
- case "symbol":
1462
- return "symbol";
1463
- case "object":
1464
- return Array.isArray(e) ? "array" : e === null ? "null" : e.then && typeof e.then == "function" && e.catch && typeof e.catch == "function" ? "promise" : typeof Map < "u" && e instanceof Map ? "map" : typeof Set < "u" && e instanceof Set ? "set" : typeof Date < "u" && e instanceof Date ? "date" : typeof File < "u" && e instanceof File ? "file" : "object";
1465
- default:
1466
- throw new Error(`Unknown data type: ${t}`);
1467
- }
1468
- }, rn = /* @__PURE__ */ new Set(["string", "number", "symbol"]), on = /* @__PURE__ */ new Set(["string", "number", "bigint", "boolean", "symbol", "undefined"]);
1469
- function sn(e) {
1470
- return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1471
- }
1472
- function ee(e, t, n) {
1473
- const r = new e._zod.constr(t ?? e._zod.def);
1474
- return (!t || n?.parent) && (r._zod.parent = e), r;
1475
- }
1476
- function an(e) {
1477
- const t = e;
1478
- if (!t)
1479
- return {};
1480
- if (typeof t == "string")
1481
- return { error: () => t };
1482
- if (t?.message !== void 0) {
1483
- if (t?.error !== void 0)
1484
- throw new Error("Cannot specify both `message` and `error` params");
1485
- t.error = t.message;
1373
+ function Ee(e) {
1374
+ if (e == null) return e;
1375
+ if (typeof e == "string") return at(e);
1376
+ if (e instanceof Date) return e;
1377
+ if (Array.isArray(e)) return e.map(Ee);
1378
+ if (typeof e == "object") {
1379
+ const t = {};
1380
+ for (const n of Object.keys(e)) t[n] = Ee(e[n]);
1381
+ return t;
1486
1382
  }
1487
- return delete t.message, typeof t.error == "string" ? { ...t, error: () => t.error } : t;
1488
- }
1489
- function un(e) {
1490
- let t;
1491
- return new Proxy({}, {
1492
- get(n, r, i) {
1493
- return t ?? (t = e()), Reflect.get(t, r, i);
1494
- },
1495
- set(n, r, i, o) {
1496
- return t ?? (t = e()), Reflect.set(t, r, i, o);
1497
- },
1498
- has(n, r) {
1499
- return t ?? (t = e()), Reflect.has(t, r);
1500
- },
1501
- deleteProperty(n, r) {
1502
- return t ?? (t = e()), Reflect.deleteProperty(t, r);
1503
- },
1504
- ownKeys(n) {
1505
- return t ?? (t = e()), Reflect.ownKeys(t);
1506
- },
1507
- getOwnPropertyDescriptor(n, r) {
1508
- return t ?? (t = e()), Reflect.getOwnPropertyDescriptor(t, r);
1509
- },
1510
- defineProperty(n, r, i) {
1511
- return t ?? (t = e()), Reflect.defineProperty(t, r, i);
1512
- }
1513
- });
1383
+ return e;
1514
1384
  }
1515
1385
  function Je(e) {
1516
- return typeof e == "bigint" ? e.toString() + "n" : typeof e == "string" ? `"${e}"` : `${e}`;
1517
- }
1518
- function cn(e) {
1519
- return Object.keys(e).filter((t) => e[t]._zod.optin === "optional" && e[t]._zod.optout === "optional");
1520
- }
1521
- var ln = {
1522
- safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
1523
- int32: [-2147483648, 2147483647],
1524
- uint32: [0, 4294967295],
1525
- float32: [-34028234663852886e22, 34028234663852886e22],
1526
- float64: [-Number.MAX_VALUE, Number.MAX_VALUE]
1527
- }, fn = {
1528
- int64: [/* @__PURE__ */ BigInt("-9223372036854775808"), /* @__PURE__ */ BigInt("9223372036854775807")],
1529
- uint64: [/* @__PURE__ */ BigInt(0), /* @__PURE__ */ BigInt("18446744073709551615")]
1530
- };
1531
- function dn(e, t) {
1532
- const n = {}, r = e._zod.def;
1533
- for (const i in t) {
1534
- if (!(i in r.shape))
1535
- throw new Error(`Unrecognized key: "${i}"`);
1536
- t[i] && (n[i] = r.shape[i]);
1537
- }
1538
- return ee(e, {
1539
- ...e._zod.def,
1540
- shape: n,
1541
- checks: []
1542
- });
1543
- }
1544
- function pn(e, t) {
1545
- const n = { ...e._zod.def.shape }, r = e._zod.def;
1546
- for (const i in t) {
1547
- if (!(i in r.shape))
1548
- throw new Error(`Unrecognized key: "${i}"`);
1549
- t[i] && delete n[i];
1550
- }
1551
- return ee(e, {
1552
- ...e._zod.def,
1553
- shape: n,
1554
- checks: []
1555
- });
1556
- }
1557
- function mn(e, t) {
1558
- if (!He(t))
1559
- throw new Error("Invalid input to extend: expected a plain object");
1560
- const n = {
1561
- ...e._zod.def,
1562
- get shape() {
1563
- const r = { ...e._zod.def.shape, ...t };
1564
- return Ee(this, "shape", r), r;
1565
- },
1566
- checks: []
1567
- // delete existing checks
1568
- };
1569
- return ee(e, n);
1570
- }
1571
- function yn(e, t) {
1572
- return ee(e, {
1573
- ...e._zod.def,
1574
- get shape() {
1575
- const n = { ...e._zod.def.shape, ...t._zod.def.shape };
1576
- return Ee(this, "shape", n), n;
1577
- },
1578
- catchall: t._zod.def.catchall,
1579
- checks: []
1580
- // delete existing checks
1581
- });
1582
- }
1583
- function hn(e, t, n) {
1584
- const r = t._zod.def.shape, i = { ...r };
1585
- if (n)
1586
- for (const o in n) {
1587
- if (!(o in r))
1588
- throw new Error(`Unrecognized key: "${o}"`);
1589
- n[o] && (i[o] = e ? new e({
1590
- type: "optional",
1591
- innerType: r[o]
1592
- }) : r[o]);
1593
- }
1594
- else
1595
- for (const o in r)
1596
- i[o] = e ? new e({
1597
- type: "optional",
1598
- innerType: r[o]
1599
- }) : r[o];
1600
- return ee(t, {
1601
- ...t._zod.def,
1602
- shape: i,
1603
- checks: []
1604
- });
1605
- }
1606
- function bn(e, t, n) {
1607
- const r = t._zod.def.shape, i = { ...r };
1608
- if (n)
1609
- for (const o in n) {
1610
- if (!(o in i))
1611
- throw new Error(`Unrecognized key: "${o}"`);
1612
- n[o] && (i[o] = new e({
1613
- type: "nonoptional",
1614
- innerType: r[o]
1615
- }));
1616
- }
1617
- else
1618
- for (const o in r)
1619
- i[o] = new e({
1620
- type: "nonoptional",
1621
- innerType: r[o]
1622
- });
1623
- return ee(t, {
1624
- ...t._zod.def,
1625
- shape: i,
1626
- // optional: [],
1627
- checks: []
1628
- });
1629
- }
1630
- function wn(e, t = 0) {
1631
- for (let n = t; n < e.issues.length; n++)
1632
- if (e.issues[n]?.continue !== !0)
1633
- return !0;
1634
- return !1;
1635
- }
1636
- function gn(e, t) {
1637
- return t.map((n) => {
1638
- var r;
1639
- return (r = n).path ?? (r.path = []), n.path.unshift(e), n;
1640
- });
1641
- }
1642
- function se(e) {
1643
- return typeof e == "string" ? e : e?.message;
1644
- }
1645
- function _n(e, t, n) {
1646
- const r = { ...e, path: e.path ?? [] };
1647
- if (!e.message) {
1648
- const i = se(e.inst?._zod.def?.error?.(e)) ?? se(t?.error?.(e)) ?? se(n.customError?.(e)) ?? se(n.localeError?.(e)) ?? "Invalid input";
1649
- r.message = i;
1386
+ try {
1387
+ return typeof e != "string" ? e == null ? null : Ee(e) : JSON.parse(e, (t, n) => at(n));
1388
+ } catch (t) {
1389
+ return ot.error("Error parsing JSON", { error: t }), null;
1650
1390
  }
1651
- return delete r.inst, delete r.continue, t?.reportInput || delete r.input, r;
1652
1391
  }
1653
- function On(e) {
1654
- return e instanceof Set ? "set" : e instanceof Map ? "map" : e instanceof File ? "file" : "unknown";
1392
+ const He = "db.collection.name", We = "db.operation.name";
1393
+ function Q(e, t, n) {
1394
+ return n();
1655
1395
  }
1656
- function $n(e) {
1657
- return Array.isArray(e) ? "array" : typeof e == "string" ? "string" : "unknown";
1658
- }
1659
- function vn(...e) {
1660
- const [t, n, r] = e;
1661
- return typeof t == "string" ? {
1662
- message: t,
1663
- code: "custom",
1664
- input: n,
1665
- inst: r
1666
- } : { ...t };
1667
- }
1668
- function Nn(e) {
1669
- return Object.entries(e).filter(([t, n]) => Number.isNaN(Number.parseInt(t, 10))).map((t) => t[1]);
1670
- }
1671
- var Sn = class {
1672
- constructor(...e) {
1673
- }
1674
- };
1675
- Ge(
1676
- "a-z",
1677
- "0-9",
1678
- "A-Z",
1679
- "-_"
1680
- );
1681
- function An(e, t, n) {
1682
- return n === "update" ? e === void 0 && t.onUpdate !== void 0 ? typeof t.onUpdate == "function" ? t.onUpdate() : t.onUpdate : e : e == null && t.defaultValue !== void 0 ? typeof t.defaultValue == "function" ? t.defaultValue() : t.defaultValue : e;
1683
- }
1684
- let fe = [], z = -1;
1685
- const In = (e) => (t) => t(e), Tn = ({
1686
- adapter: e,
1687
- config: t
1688
- }) => (n) => {
1689
- const r = Math.random().toString(36).substring(2, 15), i = {
1396
+ let ge = [], K = -1;
1397
+ const Yt = (e) => (t) => t(e), Xt = ({ adapter: e, config: t }) => (n) => {
1398
+ const i = Math.random().toString(36).substring(2, 15), r = {
1690
1399
  ...t,
1691
1400
  supportsBooleans: t.supportsBooleans ?? !0,
1692
1401
  supportsDates: t.supportsDates ?? !0,
1693
1402
  supportsJSON: t.supportsJSON ?? !1,
1694
1403
  adapterName: t.adapterName ?? t.adapterId,
1695
1404
  supportsNumericIds: t.supportsNumericIds ?? !0,
1405
+ supportsUUIDs: t.supportsUUIDs ?? !1,
1406
+ supportsArrays: t.supportsArrays ?? !1,
1696
1407
  transaction: t.transaction ?? !1,
1697
1408
  disableTransformInput: t.disableTransformInput ?? !1,
1698
- disableTransformOutput: t.disableTransformOutput ?? !1
1699
- };
1700
- if (n.advanced?.database?.useNumberId === !0 && i.supportsNumericIds === !1)
1701
- throw new Error(
1702
- `[${i.adapterName}] Your database or database adapter does not support numeric ids. Please disable "useNumberId" in your config.`
1703
- );
1704
- const o = De(n), f = ({
1705
- field: u,
1706
- model: m
1707
- }) => {
1708
- if (u === "id" || u === "_id")
1709
- return "id";
1710
- const p = s(m);
1711
- let d = o[p]?.fields[u];
1712
- if (!d) {
1713
- const h = Object.entries(o[p].fields).find(
1714
- ([b, O]) => O.fieldName === u
1715
- );
1716
- h && (d = h[1], u = h[0]);
1717
- }
1718
- if (!d)
1719
- throw l(`Field ${u} not found in model ${p}`), l("Schema:", o), new Error(`Field ${u} not found in model ${p}`);
1720
- return u;
1721
- }, s = (u) => {
1722
- if (i.usePlural && u.charAt(u.length - 1) === "s") {
1723
- let p = u.slice(0, -1), d = o[p] ? p : void 0;
1724
- if (d || (d = Object.entries(o).find(
1725
- ([h, b]) => b.modelName === p
1726
- )?.[0]), d)
1727
- return d;
1728
- }
1729
- let m = o[u] ? u : void 0;
1730
- if (m || (m = Object.entries(o).find(([p, d]) => d.modelName === u)?.[0]), !m)
1731
- throw l(`Model "${u}" not found in schema`), l("Schema:", o), new Error(`Model "${u}" not found in schema`);
1732
- return m;
1733
- }, a = (u) => {
1734
- const m = s(u), p = i && i.usePlural;
1735
- return o && o[m] && o[m].modelName !== u ? p ? `${o[m].modelName}s` : o[m].modelName : p ? `${u}s` : u;
1409
+ disableTransformOutput: t.disableTransformOutput ?? !1,
1410
+ disableTransformJoin: t.disableTransformJoin ?? !1
1736
1411
  };
1737
- function c({
1738
- model: u,
1739
- field: m
1740
- }) {
1741
- const p = s(u), d = f({ model: p, field: m });
1742
- return o[p]?.fields[d]?.fieldName || d;
1743
- }
1744
- const l = (...u) => {
1745
- if (i.debugLogs === !0 || typeof i.debugLogs == "object") {
1746
- if (typeof i.debugLogs == "object" && "isRunningAdapterTests" in i.debugLogs) {
1747
- i.debugLogs.isRunningAdapterTests && (u.shift(), fe.push({ instance: r, args: u }));
1412
+ if (n.advanced?.database?.generateId === "serial" && r.supportsNumericIds === !1) throw new re(`[${r.adapterName}] Your database or database adapter does not support numeric ids. Please disable "useNumberId" in your config.`);
1413
+ const s = Ge(n), a = (...l) => {
1414
+ if (r.debugLogs === !0 || typeof r.debugLogs == "object") {
1415
+ const b = De({ level: "info" });
1416
+ if (typeof r.debugLogs == "object" && "isRunningAdapterTests" in r.debugLogs) {
1417
+ r.debugLogs.isRunningAdapterTests && (l.shift(), ge.push({
1418
+ instance: i,
1419
+ args: l
1420
+ }));
1748
1421
  return;
1749
1422
  }
1750
- if (typeof i.debugLogs == "object" && i.debugLogs.logCondition && !i.debugLogs.logCondition?.())
1751
- return;
1752
- if (typeof u[0] == "object" && "method" in u[0]) {
1753
- const m = u.shift().method;
1754
- if (typeof i.debugLogs == "object") {
1755
- if (m === "create" && !i.debugLogs.create)
1756
- return;
1757
- if (m === "update" && !i.debugLogs.update)
1758
- return;
1759
- if (m === "updateMany" && !i.debugLogs.updateMany)
1760
- return;
1761
- if (m === "findOne" && !i.debugLogs.findOne)
1762
- return;
1763
- if (m === "findMany" && !i.debugLogs.findMany)
1764
- return;
1765
- if (m === "delete" && !i.debugLogs.delete)
1766
- return;
1767
- if (m === "deleteMany" && !i.debugLogs.deleteMany)
1768
- return;
1769
- if (m === "count" && !i.debugLogs.count)
1770
- return;
1423
+ if (typeof r.debugLogs == "object" && r.debugLogs.logCondition && !r.debugLogs.logCondition?.()) return;
1424
+ if (typeof l[0] == "object" && "method" in l[0]) {
1425
+ const h = l.shift().method;
1426
+ if (typeof r.debugLogs == "object") {
1427
+ if (h === "create" && !r.debugLogs.create) return;
1428
+ if (h === "update" && !r.debugLogs.update) return;
1429
+ if (h === "updateMany" && !r.debugLogs.updateMany) return;
1430
+ if (h === "findOne" && !r.debugLogs.findOne) return;
1431
+ if (h === "findMany" && !r.debugLogs.findMany) return;
1432
+ if (h === "delete" && !r.debugLogs.delete) return;
1433
+ if (h === "deleteMany" && !r.debugLogs.deleteMany) return;
1434
+ if (h === "count" && !r.debugLogs.count) return;
1771
1435
  }
1772
- Y.info(`[${i.adapterName}]`, ...u);
1773
- } else
1774
- Y.info(`[${i.adapterName}]`, ...u);
1436
+ b.info(`[${r.adapterName}]`, ...l);
1437
+ } else b.info(`[${r.adapterName}]`, ...l);
1775
1438
  }
1776
- }, y = ({
1777
- customModelName: u,
1778
- forceAllowId: m
1779
- }) => {
1780
- const p = !i.disableIdGeneration && !n.advanced?.database?.useNumberId && !m, d = s(u ?? "id");
1781
- return {
1782
- type: n.advanced?.database?.useNumberId ? "number" : "string",
1783
- required: !!p,
1784
- ...p ? {
1785
- defaultValue() {
1786
- if (i.disableIdGeneration) return;
1787
- const h = n.advanced?.database?.useNumberId;
1788
- let b = n.advanced?.database?.generateId;
1789
- if (n.advanced?.generateId !== void 0 && (Y.warn(
1790
- "Your Better Auth config includes advanced.generateId which is deprecated. Please use advanced.database.generateId instead. This will be removed in future releases."
1791
- ), b = n.advanced?.generateId), !(b === !1 || h))
1792
- return b ? b({
1793
- model: d
1794
- }) : i.customIdGenerator ? i.customIdGenerator({ model: d }) : jt();
1795
- }
1796
- } : {}
1797
- };
1798
- }, w = ({
1799
- model: u,
1800
- field: m
1801
- }) => {
1802
- const p = s(u), d = f({
1803
- field: m,
1804
- model: p
1805
- }), h = o[p].fields;
1806
- return h.id = y({ customModelName: p }), h[d];
1807
- }, S = async (u, m, p, d) => {
1808
- const h = {}, b = o[m].fields, O = i.mapKeysTransformInput ?? {};
1809
- !i.disableIdGeneration && !n.advanced?.database?.useNumberId && (b.id = y({
1810
- customModelName: m,
1811
- forceAllowId: d && "id" in u
1812
- }));
1813
- for (const g in b) {
1814
- const N = u[g], A = b[g];
1815
- let _ = O[g] || b[g].fieldName || g;
1816
- if (N === void 0 && (A.defaultValue === void 0 && !A.transform?.input && !(p === "update" && A.onUpdate) || p === "update" && !A.onUpdate))
1817
- continue;
1818
- let $ = An(N, A, p);
1819
- A.transform?.input && ($ = await A.transform.input($)), A.references?.field === "id" && n.advanced?.database?.useNumberId ? Array.isArray($) ? $ = $.map((te) => te !== null ? Number(te) : null) : $ = $ !== null ? Number($) : null : i.supportsJSON === !1 && typeof $ == "object" && A.type === "json" ? $ = JSON.stringify($) : i.supportsDates === !1 && $ instanceof Date && A.type === "date" ? $ = $.toISOString() : i.supportsBooleans === !1 && typeof $ == "boolean" && ($ = $ ? 1 : 0), i.customTransformInput && ($ = i.customTransformInput({
1820
- data: $,
1821
- action: p,
1822
- field: _,
1823
- fieldAttributes: A,
1824
- model: m,
1825
- schema: o,
1439
+ }, u = De(n.logger), o = de({
1440
+ usePlural: r.usePlural,
1441
+ schema: s
1442
+ }), c = qe({
1443
+ usePlural: r.usePlural,
1444
+ schema: s
1445
+ }), d = Jt({
1446
+ usePlural: r.usePlural,
1447
+ schema: s
1448
+ }), f = Gt({
1449
+ schema: s,
1450
+ usePlural: r.usePlural
1451
+ }), g = st({
1452
+ schema: s,
1453
+ options: n,
1454
+ usePlural: r.usePlural,
1455
+ disableIdGeneration: r.disableIdGeneration,
1456
+ customIdGenerator: r.customIdGenerator,
1457
+ supportsUUIDs: r.supportsUUIDs
1458
+ }), $ = Kt({
1459
+ schema: s,
1460
+ options: n,
1461
+ usePlural: r.usePlural,
1462
+ disableIdGeneration: r.disableIdGeneration,
1463
+ customIdGenerator: r.customIdGenerator
1464
+ }), v = async (l, b, h, y) => {
1465
+ const p = {}, N = s[b].fields, A = r.mapKeysTransformInput ?? {}, w = n.advanced?.database?.generateId === "serial";
1466
+ N.id = g({
1467
+ customModelName: b,
1468
+ forceAllowId: y && "id" in l
1469
+ });
1470
+ for (const _ in N) {
1471
+ let S = l[_];
1472
+ const m = N[_], I = A[_] || N[_].fieldName || _;
1473
+ if (S === void 0 && (m.defaultValue === void 0 && !m.transform?.input && !(h === "update" && m.onUpdate) || h === "update" && !m.onUpdate)) continue;
1474
+ if (m && m.type === "date" && !(S instanceof Date) && typeof S == "string") try {
1475
+ S = new Date(S);
1476
+ } catch {
1477
+ u.error("[Adapter Factory] Failed to convert string to date", {
1478
+ value: S,
1479
+ field: _
1480
+ });
1481
+ }
1482
+ let O = Ht(S, m, h);
1483
+ m.transform?.input && (O = await m.transform.input(O)), m.references?.field === "id" && w ? Array.isArray(O) ? O = O.map((F) => F !== null ? Number(F) : null) : O = O !== null ? Number(O) : null : r.supportsJSON === !1 && typeof O == "object" && m.type === "json" || r.supportsArrays === !1 && Array.isArray(O) && (m.type === "string[]" || m.type === "number[]") ? O = JSON.stringify(O) : r.supportsDates === !1 && O instanceof Date && m.type === "date" ? O = O.toISOString() : r.supportsBooleans === !1 && typeof O == "boolean" && (O = O ? 1 : 0), r.customTransformInput && (O = r.customTransformInput({
1484
+ data: O,
1485
+ action: h,
1486
+ field: I,
1487
+ fieldAttributes: m,
1488
+ model: d(b),
1489
+ schema: s,
1826
1490
  options: n
1827
- })), $ !== void 0 && (h[_] = $);
1491
+ })), O !== void 0 && (p[I] = O);
1828
1492
  }
1829
- return h;
1830
- }, C = async (u, m, p = []) => {
1831
- if (!u) return null;
1832
- const d = i.mapKeysTransformOutput ?? {}, h = {}, b = o[m].fields, O = Object.entries(d).find(
1833
- ([g, N]) => N === "id"
1834
- )?.[0];
1835
- b[O ?? "id"] = {
1836
- type: n.advanced?.database?.useNumberId ? "number" : "string"
1493
+ return p;
1494
+ }, j = async (l, b, h = [], y) => {
1495
+ const p = async (w, _, S = []) => {
1496
+ if (!w) return null;
1497
+ const m = r.mapKeysTransformOutput ?? {}, I = {}, O = s[o(_)].fields, F = Object.entries(m).find(([x, R]) => R === "id")?.[0];
1498
+ O[F ?? "id"] = { type: n.advanced?.database?.generateId === "serial" ? "number" : "string" };
1499
+ for (const x in O) {
1500
+ if (S.length && !S.includes(x)) continue;
1501
+ const R = O[x];
1502
+ if (R) {
1503
+ const G = R.fieldName || x;
1504
+ let M = w[Object.entries(m).find(([an, ut]) => ut === G)?.[0] || G];
1505
+ R.transform?.output && (M = await R.transform.output(M));
1506
+ const ne = m[x] || x;
1507
+ G === "id" || R.references?.field === "id" ? typeof M < "u" && M !== null && (M = String(M)) : r.supportsJSON === !1 && typeof M == "string" && R.type === "json" || r.supportsArrays === !1 && typeof M == "string" && (R.type === "string[]" || R.type === "number[]") ? M = Je(M) : r.supportsDates === !1 && typeof M == "string" && R.type === "date" ? M = new Date(M) : r.supportsBooleans === !1 && typeof M == "number" && R.type === "boolean" && (M = M === 1), r.customTransformOutput && (M = r.customTransformOutput({
1508
+ data: M,
1509
+ field: ne,
1510
+ fieldAttributes: R,
1511
+ select: S,
1512
+ model: d(_),
1513
+ schema: s,
1514
+ options: n
1515
+ })), I[ne] = M;
1516
+ }
1517
+ }
1518
+ return I;
1837
1519
  };
1838
- for (const g in b) {
1839
- if (p.length && !p.includes(g))
1840
- continue;
1841
- const N = b[g];
1842
- if (N) {
1843
- const A = N.fieldName || g;
1844
- let _ = u[Object.entries(d).find(
1845
- ([te, Xe]) => Xe === A
1846
- )?.[0] || A];
1847
- N.transform?.output && (_ = await N.transform.output(_));
1848
- let $ = d[g] || g;
1849
- A === "id" || N.references?.field === "id" ? typeof _ < "u" && _ !== null && (_ = String(_)) : i.supportsJSON === !1 && typeof _ == "string" && N.type === "json" ? _ = xt(_) : i.supportsDates === !1 && typeof _ == "string" && N.type === "date" ? _ = new Date(_) : i.supportsBooleans === !1 && typeof _ == "number" && N.type === "boolean" && (_ = _ === 1), i.customTransformOutput && (_ = i.customTransformOutput({
1850
- data: _,
1851
- field: $,
1852
- fieldAttributes: N,
1853
- select: p,
1854
- model: m,
1855
- schema: o,
1856
- options: n
1857
- })), h[$] = _;
1520
+ if (!y || Object.keys(y).length === 0) return await p(l, b, h);
1521
+ b = o(b);
1522
+ const N = await p(l, b, h), A = Object.entries(y).map(([w, _]) => ({
1523
+ modelName: d(w),
1524
+ defaultModelName: o(w),
1525
+ joinConfig: _
1526
+ }));
1527
+ if (!l) return null;
1528
+ for (const { modelName: w, defaultModelName: _, joinConfig: S } of A) {
1529
+ let m = await (async () => n.experimental?.joins ? l[w] : await H({
1530
+ baseModel: b,
1531
+ baseData: N,
1532
+ joinModel: w,
1533
+ specificJoinConfig: S
1534
+ }))();
1535
+ m == null && (m = S.relation === "one-to-one" ? null : []), S.relation === "one-to-many" && !Array.isArray(m) && (m = [m]);
1536
+ const I = [];
1537
+ if (Array.isArray(m)) for (const O of m) {
1538
+ const F = await p(O, w, []);
1539
+ I.push(F);
1540
+ }
1541
+ else {
1542
+ const O = await p(m, w, []);
1543
+ I.push(O);
1858
1544
  }
1545
+ N[_] = (S.relation === "one-to-one" ? I[0] : I) ?? null;
1859
1546
  }
1860
- return h;
1861
- }, x = ({
1862
- model: u,
1863
- where: m
1864
- }) => {
1865
- if (!m) return;
1866
- const p = i.mapKeysTransformInput ?? {};
1867
- return m.map((d) => {
1868
- const {
1869
- field: h,
1870
- value: b,
1871
- operator: O = "eq",
1872
- connector: g = "AND"
1873
- } = d;
1874
- if (O === "in" && !Array.isArray(b))
1875
- throw new Error("Value must be an array");
1876
- const N = s(u), A = f({
1877
- field: h,
1878
- model: u
1879
- }), _ = p[A] || c({
1880
- field: A,
1881
- model: N
1882
- }), $ = w({
1883
- field: A,
1884
- model: N
1885
- });
1886
- return (A === "id" || $.references?.field === "id") && n.advanced?.database?.useNumberId ? Array.isArray(b) ? {
1887
- operator: O,
1888
- connector: g,
1889
- field: _,
1890
- value: b.map(Number)
1891
- } : {
1892
- operator: O,
1893
- connector: g,
1894
- field: _,
1895
- value: Number(b)
1896
- } : {
1897
- operator: O,
1898
- connector: g,
1899
- field: _,
1900
- value: b
1547
+ return N;
1548
+ }, P = ({ model: l, where: b, action: h }) => {
1549
+ if (!b) return;
1550
+ const y = r.mapKeysTransformInput ?? {};
1551
+ return b.map((p) => {
1552
+ const { field: N, value: A, operator: w = "eq", connector: _ = "AND", mode: S = "sensitive" } = p;
1553
+ if (w === "in" && !Array.isArray(A))
1554
+ throw new re("Value must be an array");
1555
+ let m = A;
1556
+ const I = o(l), O = c({
1557
+ field: N,
1558
+ model: l
1559
+ }), F = y[O] || f({
1560
+ field: O,
1561
+ model: I
1562
+ }), x = $({
1563
+ field: O,
1564
+ model: I
1565
+ }), R = n.advanced?.database?.generateId === "serial";
1566
+ if ((O === "id" || x.references?.field === "id") && R && (Array.isArray(A) ? m = A.map(Number) : m = Number(A)), x.type === "date" && A instanceof Date && !r.supportsDates && (m = A.toISOString()), x.type === "boolean" && typeof m == "string" && (m = m === "true"), x.type === "number") {
1567
+ if (typeof m == "string" && m.trim() !== "") {
1568
+ const G = Number(m);
1569
+ Number.isNaN(G) || (m = G);
1570
+ } else if (Array.isArray(m)) {
1571
+ const G = m.map((M) => typeof M == "string" && M.trim() !== "" ? Number(M) : NaN);
1572
+ G.every((M) => !Number.isNaN(M)) && (m = G);
1573
+ }
1574
+ }
1575
+ if (x.type === "boolean" && typeof m == "boolean" && !r.supportsBooleans && (m = m ? 1 : 0), x.type === "json" && typeof A == "object" && !r.supportsJSON) try {
1576
+ m = JSON.stringify(A);
1577
+ } catch (G) {
1578
+ throw new Error(`Failed to stringify JSON value for field ${F}`, { cause: G });
1579
+ }
1580
+ return r.customTransformInput && (m = r.customTransformInput({
1581
+ data: m,
1582
+ fieldAttributes: x,
1583
+ field: F,
1584
+ model: d(l),
1585
+ schema: s,
1586
+ options: n,
1587
+ action: h
1588
+ })), {
1589
+ operator: w,
1590
+ connector: _,
1591
+ field: F,
1592
+ value: m,
1593
+ mode: S
1594
+ };
1595
+ });
1596
+ }, X = (l, b, h) => {
1597
+ if (!b || Object.keys(b).length === 0) return;
1598
+ const y = {};
1599
+ for (const [p, N] of Object.entries(b)) {
1600
+ if (!N) continue;
1601
+ const A = o(p), w = o(l);
1602
+ let _ = Object.entries(s[A].fields).filter(([M, ne]) => ne.references && o(ne.references.model) === w), S = !0;
1603
+ if (_.length || (_ = Object.entries(s[w].fields).filter(([M, ne]) => ne.references && o(ne.references.model) === A), S = !1), _.length) {
1604
+ if (_.length > 1) throw new re(`Multiple foreign keys found for model ${p} and base model ${l} while performing join operation. Only one foreign key is supported.`);
1605
+ } else throw new re(`No foreign key found for model ${p} and base model ${l} while performing join operation.`);
1606
+ const [m, I] = _[0];
1607
+ if (!I.references) throw new re(`No references found for foreign key ${m} on model ${p} while performing join operation.`);
1608
+ let O, F, x;
1609
+ S ? (x = I.references.field, O = f({
1610
+ model: l,
1611
+ field: x
1612
+ }), F = f({
1613
+ model: p,
1614
+ field: m
1615
+ })) : (x = m, O = f({
1616
+ model: l,
1617
+ field: x
1618
+ }), F = f({
1619
+ model: p,
1620
+ field: I.references.field
1621
+ })), h && !h.includes(x) && h.push(x);
1622
+ const R = F === "id" ? !0 : I.unique ?? !1;
1623
+ let G = n.advanced?.database?.defaultFindManyLimit ?? 100;
1624
+ R ? G = 1 : typeof N == "object" && typeof N.limit == "number" && (G = N.limit), y[d(p)] = {
1625
+ on: {
1626
+ from: O,
1627
+ to: F
1628
+ },
1629
+ limit: G,
1630
+ relation: R ? "one-to-one" : "one-to-many"
1901
1631
  };
1632
+ }
1633
+ return {
1634
+ join: y,
1635
+ select: h
1636
+ };
1637
+ }, H = async ({ baseModel: l, baseData: b, joinModel: h, specificJoinConfig: y }) => {
1638
+ if (!b) return b;
1639
+ const p = d(h), N = y.on.to, A = b[c({
1640
+ field: y.on.from,
1641
+ model: l
1642
+ })];
1643
+ if (A == null) return y.relation === "one-to-one" ? null : [];
1644
+ let w;
1645
+ const _ = P({
1646
+ model: p,
1647
+ where: [{
1648
+ field: N,
1649
+ value: A,
1650
+ operator: "eq",
1651
+ connector: "AND"
1652
+ }],
1653
+ action: "findOne"
1902
1654
  });
1903
- }, E = e({
1655
+ try {
1656
+ if (y.relation === "one-to-one") w = await Q(`db findOne ${p}`, {
1657
+ [We]: "findOne",
1658
+ [He]: p
1659
+ }, () => C.findOne({
1660
+ model: p,
1661
+ where: _
1662
+ }));
1663
+ else {
1664
+ const S = y.limit ?? n.advanced?.database?.defaultFindManyLimit ?? 100;
1665
+ w = await Q(`db findMany ${p}`, {
1666
+ [We]: "findMany",
1667
+ [He]: p
1668
+ }, () => C.findMany({
1669
+ model: p,
1670
+ where: _,
1671
+ limit: S
1672
+ }));
1673
+ }
1674
+ } catch (S) {
1675
+ throw u.error(`Failed to query fallback join for model ${p}:`, {
1676
+ where: _,
1677
+ limit: y.limit
1678
+ }), console.error(S), S;
1679
+ }
1680
+ return w;
1681
+ }, C = e({
1904
1682
  options: n,
1905
- schema: o,
1906
- debugLog: l,
1907
- getFieldName: c,
1908
- getModelName: a,
1909
- getDefaultModelName: s,
1910
- getDefaultFieldName: f,
1911
- getFieldAttributes: w,
1912
- transformInput: S,
1913
- transformOutput: C,
1914
- transformWhereClause: x
1683
+ schema: s,
1684
+ debugLog: a,
1685
+ getFieldName: f,
1686
+ getModelName: d,
1687
+ getDefaultModelName: o,
1688
+ getDefaultFieldName: c,
1689
+ getFieldAttributes: $,
1690
+ transformInput: v,
1691
+ transformOutput: j,
1692
+ transformWhereClause: P
1915
1693
  });
1916
- let B = null;
1917
- const V = {
1918
- transaction: async (u) => (B || (i.transaction ? (Y.debug(
1919
- `[${i.adapterName}] - Using provided transaction implementation.`
1920
- ), B = i.transaction) : (typeof i.debugLogs == "object" && "isRunningAdapterTests" in i.debugLogs && i.debugLogs.isRunningAdapterTests || Y.warn(
1921
- `[${i.adapterName}] - Transactions are not supported. Executing operations sequentially.`
1922
- ), B = In(V))), B(u)),
1923
- create: async ({
1924
- data: u,
1925
- model: m,
1926
- select: p,
1927
- forceAllowId: d = !1
1928
- }) => {
1929
- z++;
1930
- let h = z;
1931
- const b = a(m);
1932
- if (m = s(m), "id" in u && !d) {
1933
- Y.warn(
1934
- `[${i.adapterName}] - You are trying to create a record with an id. This is not allowed as we handle id generation for you, unless you pass in the \`forceAllowId\` parameter. The id will be ignored.`
1935
- );
1936
- const _ = new Error().stack?.split(`
1937
- `).filter(($, te) => te !== 1).join(`
1694
+ let ue = null;
1695
+ const Ve = {
1696
+ transaction: async (l) => (ue || (r.transaction ? (u.debug(`[${r.adapterName}] - Using provided transaction implementation.`), ue = r.transaction) : ue = Yt(Ve)), ue(l)),
1697
+ create: async ({ data: l, model: b, select: h, forceAllowId: y = !1 }) => {
1698
+ K++;
1699
+ const p = K, N = d(b);
1700
+ if (b = o(b), "id" in l && typeof l.id < "u" && !y) {
1701
+ u.warn(`[${r.adapterName}] - You are trying to create a record with an id. This is not allowed as we handle id generation for you, unless you pass in the \`forceAllowId\` parameter. The id will be ignored.`);
1702
+ const S = (/* @__PURE__ */ new Error()).stack?.split(`
1703
+ `).filter((m, I) => I !== 1).join(`
1938
1704
  `).replace("Error:", "Create method with `id` being called at:");
1939
- console.log(_), u.id = void 0;
1705
+ console.log(S), l.id = void 0;
1940
1706
  }
1941
- l(
1942
- { method: "create" },
1943
- `${I(h)} ${T(1, 4)}`,
1944
- `${R("create")} ${j("Unsafe Input")}:`,
1945
- { model: b, data: u }
1946
- );
1947
- let O = u;
1948
- i.disableTransformInput || (O = await S(
1949
- u,
1950
- m,
1951
- "create",
1952
- d
1953
- )), l(
1954
- { method: "create" },
1955
- `${I(h)} ${T(2, 4)}`,
1956
- `${R("create")} ${j("Parsed Input")}:`,
1957
- { model: b, data: O }
1958
- );
1959
- const g = await E.create({ data: O, model: b });
1960
- l(
1961
- { method: "create" },
1962
- `${I(h)} ${T(3, 4)}`,
1963
- `${R("create")} ${j("DB Result")}:`,
1964
- { model: b, res: g }
1965
- );
1966
- let N = g;
1967
- return i.disableTransformOutput || (N = await C(g, m, p)), l(
1968
- { method: "create" },
1969
- `${I(h)} ${T(4, 4)}`,
1970
- `${R("create")} ${j("Parsed Result")}:`,
1971
- { model: b, data: N }
1972
- ), N;
1973
- },
1974
- update: async ({
1975
- model: u,
1976
- where: m,
1977
- update: p
1978
- }) => {
1979
- z++;
1980
- let d = z;
1981
- u = s(u);
1982
- const h = a(u), b = x({
1983
- model: u,
1984
- where: m
1707
+ a({ method: "create" }, `${D(p)} ${E(1, 4)}`, `${k("create")} ${q("Unsafe Input")}:`, {
1708
+ model: N,
1709
+ data: l
1985
1710
  });
1986
- l(
1987
- { method: "update" },
1988
- `${I(d)} ${T(1, 4)}`,
1989
- `${R("update")} ${j("Unsafe Input")}:`,
1990
- { model: h, data: p }
1991
- );
1992
- let O = p;
1993
- i.disableTransformInput || (O = await S(p, u, "update")), l(
1994
- { method: "update" },
1995
- `${I(d)} ${T(2, 4)}`,
1996
- `${R("update")} ${j("Parsed Input")}:`,
1997
- { model: h, data: O }
1998
- );
1999
- const g = await E.update({
2000
- model: h,
2001
- where: b,
2002
- update: O
1711
+ let A = l;
1712
+ r.disableTransformInput || (A = await v(l, b, "create", y)), a({ method: "create" }, `${D(p)} ${E(2, 4)}`, `${k("create")} ${q("Parsed Input")}:`, {
1713
+ model: N,
1714
+ data: A
2003
1715
  });
2004
- l(
2005
- { method: "update" },
2006
- `${I(d)} ${T(3, 4)}`,
2007
- `${R("update")} ${j("DB Result")}:`,
2008
- { model: h, data: g }
2009
- );
2010
- let N = g;
2011
- return i.disableTransformOutput || (N = await C(g, u)), l(
2012
- { method: "update" },
2013
- `${I(d)} ${T(4, 4)}`,
2014
- `${R("update")} ${j("Parsed Result")}:`,
2015
- { model: h, data: N }
2016
- ), N;
2017
- },
2018
- updateMany: async ({
2019
- model: u,
2020
- where: m,
2021
- update: p
2022
- }) => {
2023
- z++;
2024
- let d = z;
2025
- const h = a(u), b = x({
2026
- model: u,
2027
- where: m
1716
+ const w = await Q(`db create ${N}`, {}, () => C.create({
1717
+ data: A,
1718
+ model: N
1719
+ }));
1720
+ a({ method: "create" }, `${D(p)} ${E(3, 4)}`, `${k("create")} ${q("DB Result")}:`, {
1721
+ model: N,
1722
+ res: w
2028
1723
  });
2029
- u = s(u), l(
2030
- { method: "updateMany" },
2031
- `${I(d)} ${T(1, 4)}`,
2032
- `${R("updateMany")} ${j("Unsafe Input")}:`,
2033
- { model: h, data: p }
2034
- );
2035
- let O = p;
2036
- i.disableTransformInput || (O = await S(p, u, "update")), l(
2037
- { method: "updateMany" },
2038
- `${I(d)} ${T(2, 4)}`,
2039
- `${R("updateMany")} ${j("Parsed Input")}:`,
2040
- { model: h, data: O }
2041
- );
2042
- const g = await E.updateMany({
2043
- model: h,
1724
+ let _ = w;
1725
+ return r.disableTransformOutput || (_ = await j(w, b, h, void 0)), a({ method: "create" }, `${D(p)} ${E(4, 4)}`, `${k("create")} ${q("Parsed Result")}:`, {
1726
+ model: N,
1727
+ data: _
1728
+ }), _;
1729
+ },
1730
+ update: async ({ model: l, where: b, update: h }) => {
1731
+ K++;
1732
+ const y = K;
1733
+ l = o(l);
1734
+ const p = d(l), N = P({
1735
+ model: l,
2044
1736
  where: b,
2045
- update: O
1737
+ action: "update"
1738
+ });
1739
+ a({ method: "update" }, `${D(y)} ${E(1, 4)}`, `${k("update")} ${q("Unsafe Input")}:`, {
1740
+ model: p,
1741
+ data: h
1742
+ });
1743
+ let A = h;
1744
+ r.disableTransformInput || (A = await v(h, l, "update")), a({ method: "update" }, `${D(y)} ${E(2, 4)}`, `${k("update")} ${q("Parsed Input")}:`, {
1745
+ model: p,
1746
+ data: A
1747
+ });
1748
+ const w = await Q(`db update ${p}`, {}, () => C.update({
1749
+ model: p,
1750
+ where: N,
1751
+ update: A
1752
+ }));
1753
+ a({ method: "update" }, `${D(y)} ${E(3, 4)}`, `${k("update")} ${q("DB Result")}:`, {
1754
+ model: p,
1755
+ data: w
2046
1756
  });
2047
- return l(
2048
- { method: "updateMany" },
2049
- `${I(d)} ${T(3, 4)}`,
2050
- `${R("updateMany")} ${j("DB Result")}:`,
2051
- { model: h, data: g }
2052
- ), l(
2053
- { method: "updateMany" },
2054
- `${I(d)} ${T(4, 4)}`,
2055
- `${R("updateMany")} ${j("Parsed Result")}:`,
2056
- { model: h, data: g }
2057
- ), g;
1757
+ let _ = w;
1758
+ return r.disableTransformOutput || (_ = await j(w, l, void 0, void 0)), a({ method: "update" }, `${D(y)} ${E(4, 4)}`, `${k("update")} ${q("Parsed Result")}:`, {
1759
+ model: p,
1760
+ data: _
1761
+ }), _;
2058
1762
  },
2059
- findOne: async ({
2060
- model: u,
2061
- where: m,
2062
- select: p
2063
- }) => {
2064
- z++;
2065
- let d = z;
2066
- const h = a(u), b = x({
2067
- model: u,
2068
- where: m
1763
+ updateMany: async ({ model: l, where: b, update: h }) => {
1764
+ K++;
1765
+ const y = K, p = d(l), N = P({
1766
+ model: l,
1767
+ where: b,
1768
+ action: "updateMany"
1769
+ });
1770
+ l = o(l), a({ method: "updateMany" }, `${D(y)} ${E(1, 4)}`, `${k("updateMany")} ${q("Unsafe Input")}:`, {
1771
+ model: p,
1772
+ data: h
1773
+ });
1774
+ let A = h;
1775
+ r.disableTransformInput || (A = await v(h, l, "update")), a({ method: "updateMany" }, `${D(y)} ${E(2, 4)}`, `${k("updateMany")} ${q("Parsed Input")}:`, {
1776
+ model: p,
1777
+ data: A
2069
1778
  });
2070
- u = s(u), l(
2071
- { method: "findOne" },
2072
- `${I(d)} ${T(1, 3)}`,
2073
- `${R("findOne")}:`,
2074
- { model: h, where: b, select: p }
2075
- );
2076
- const O = await E.findOne({
2077
- model: h,
1779
+ const w = await Q(`db updateMany ${p}`, {}, () => C.updateMany({
1780
+ model: p,
1781
+ where: N,
1782
+ update: A
1783
+ }));
1784
+ return a({ method: "updateMany" }, `${D(y)} ${E(3, 4)}`, `${k("updateMany")} ${q("DB Result")}:`, {
1785
+ model: p,
1786
+ data: w
1787
+ }), a({ method: "updateMany" }, `${D(y)} ${E(4, 4)}`, `${k("updateMany")} ${q("Parsed Result")}:`, {
1788
+ model: p,
1789
+ data: w
1790
+ }), w;
1791
+ },
1792
+ findOne: async ({ model: l, where: b, select: h, join: y }) => {
1793
+ K++;
1794
+ const p = K, N = d(l), A = P({
1795
+ model: l,
2078
1796
  where: b,
2079
- select: p
1797
+ action: "findOne"
1798
+ });
1799
+ l = o(l);
1800
+ let w, _ = !0;
1801
+ if (r.disableTransformJoin)
1802
+ w = y;
1803
+ else {
1804
+ const I = X(l, y, h);
1805
+ I && (w = I.join, h = I.select), !n.experimental?.joins && w && Object.keys(w).length > 0 && (_ = !1);
1806
+ }
1807
+ a({ method: "findOne" }, `${D(p)} ${E(1, 3)}`, `${k("findOne")}:`, {
1808
+ model: N,
1809
+ where: A,
1810
+ select: h,
1811
+ join: w
1812
+ });
1813
+ const S = await Q(`db findOne ${N}`, {}, () => C.findOne({
1814
+ model: N,
1815
+ where: A,
1816
+ select: h,
1817
+ join: _ ? w : void 0
1818
+ }));
1819
+ a({ method: "findOne" }, `${D(p)} ${E(2, 3)}`, `${k("findOne")} ${q("DB Result")}:`, {
1820
+ model: N,
1821
+ data: S
2080
1822
  });
2081
- l(
2082
- { method: "findOne" },
2083
- `${I(d)} ${T(2, 3)}`,
2084
- `${R("findOne")} ${j("DB Result")}:`,
2085
- { model: h, data: O }
2086
- );
2087
- let g = O;
2088
- return i.disableTransformOutput || (g = await C(O, u, p)), l(
2089
- { method: "findOne" },
2090
- `${I(d)} ${T(3, 3)}`,
2091
- `${R("findOne")} ${j("Parsed Result")}:`,
2092
- { model: h, data: g }
2093
- ), g;
1823
+ let m = S;
1824
+ return r.disableTransformOutput || (m = await j(S, l, h, w)), a({ method: "findOne" }, `${D(p)} ${E(3, 3)}`, `${k("findOne")} ${q("Parsed Result")}:`, {
1825
+ model: N,
1826
+ data: m
1827
+ }), m;
2094
1828
  },
2095
- findMany: async ({
2096
- model: u,
2097
- where: m,
2098
- limit: p,
2099
- sortBy: d,
2100
- offset: h
2101
- }) => {
2102
- z++;
2103
- let b = z;
2104
- const O = p ?? n.advanced?.database?.defaultFindManyLimit ?? 100, g = a(u), N = x({
2105
- model: u,
2106
- where: m
1829
+ findMany: async ({ model: l, where: b, limit: h, select: y, sortBy: p, offset: N, join: A }) => {
1830
+ K++;
1831
+ const w = K, _ = h ?? n.advanced?.database?.defaultFindManyLimit ?? 100, S = d(l), m = P({
1832
+ model: l,
1833
+ where: b,
1834
+ action: "findMany"
2107
1835
  });
2108
- u = s(u), l(
2109
- { method: "findMany" },
2110
- `${I(b)} ${T(1, 3)}`,
2111
- `${R("findMany")}:`,
2112
- { model: g, where: N, limit: O, sortBy: d, offset: h }
2113
- );
2114
- const A = await E.findMany({
2115
- model: g,
2116
- where: N,
2117
- limit: O,
2118
- sortBy: d,
2119
- offset: h
1836
+ l = o(l);
1837
+ let I, O = !0;
1838
+ if (r.disableTransformJoin)
1839
+ I = A;
1840
+ else {
1841
+ const R = X(l, A, y);
1842
+ R && (I = R.join, y = R.select), !n.experimental?.joins && I && Object.keys(I).length > 0 && (O = !1);
1843
+ }
1844
+ a({ method: "findMany" }, `${D(w)} ${E(1, 3)}`, `${k("findMany")}:`, {
1845
+ model: S,
1846
+ where: m,
1847
+ limit: _,
1848
+ sortBy: p,
1849
+ offset: N,
1850
+ join: I
1851
+ });
1852
+ const F = await Q(`db findMany ${S}`, {}, () => C.findMany({
1853
+ model: S,
1854
+ where: m,
1855
+ limit: _,
1856
+ select: y,
1857
+ sortBy: p,
1858
+ offset: N,
1859
+ join: O ? I : void 0
1860
+ }));
1861
+ a({ method: "findMany" }, `${D(w)} ${E(2, 3)}`, `${k("findMany")} ${q("DB Result")}:`, {
1862
+ model: S,
1863
+ data: F
2120
1864
  });
2121
- l(
2122
- { method: "findMany" },
2123
- `${I(b)} ${T(2, 3)}`,
2124
- `${R("findMany")} ${j("DB Result")}:`,
2125
- { model: g, data: A }
2126
- );
2127
- let _ = A;
2128
- return i.disableTransformOutput || (_ = await Promise.all(
2129
- A.map(async ($) => await C($, u))
2130
- )), l(
2131
- { method: "findMany" },
2132
- `${I(b)} ${T(3, 3)}`,
2133
- `${R("findMany")} ${j("Parsed Result")}:`,
2134
- { model: g, data: _ }
2135
- ), _;
1865
+ let x = F;
1866
+ return r.disableTransformOutput || (x = await Promise.all(F.map(async (R) => await j(R, l, void 0, I)))), a({ method: "findMany" }, `${D(w)} ${E(3, 3)}`, `${k("findMany")} ${q("Parsed Result")}:`, {
1867
+ model: S,
1868
+ data: x
1869
+ }), x;
2136
1870
  },
2137
- delete: async ({
2138
- model: u,
2139
- where: m
2140
- }) => {
2141
- z++;
2142
- let p = z;
2143
- const d = a(u), h = x({
2144
- model: u,
2145
- where: m
1871
+ delete: async ({ model: l, where: b }) => {
1872
+ K++;
1873
+ const h = K, y = d(l), p = P({
1874
+ model: l,
1875
+ where: b,
1876
+ action: "delete"
2146
1877
  });
2147
- u = s(u), l(
2148
- { method: "delete" },
2149
- `${I(p)} ${T(1, 2)}`,
2150
- `${R("delete")}:`,
2151
- { model: d, where: h }
2152
- ), await E.delete({
2153
- model: d,
2154
- where: h
2155
- }), l(
2156
- { method: "delete" },
2157
- `${I(p)} ${T(2, 2)}`,
2158
- `${R("delete")} ${j("DB Result")}:`,
2159
- { model: d }
2160
- );
1878
+ l = o(l), a({ method: "delete" }, `${D(h)} ${E(1, 2)}`, `${k("delete")}:`, {
1879
+ model: y,
1880
+ where: p
1881
+ }), await Q(`db delete ${y}`, {}, () => C.delete({
1882
+ model: y,
1883
+ where: p
1884
+ })), a({ method: "delete" }, `${D(h)} ${E(2, 2)}`, `${k("delete")} ${q("DB Result")}:`, { model: y });
2161
1885
  },
2162
- deleteMany: async ({
2163
- model: u,
2164
- where: m
2165
- }) => {
2166
- z++;
2167
- let p = z;
2168
- const d = a(u), h = x({
2169
- model: u,
2170
- where: m
1886
+ deleteMany: async ({ model: l, where: b }) => {
1887
+ K++;
1888
+ const h = K, y = d(l), p = P({
1889
+ model: l,
1890
+ where: b,
1891
+ action: "deleteMany"
2171
1892
  });
2172
- u = s(u), l(
2173
- { method: "deleteMany" },
2174
- `${I(p)} ${T(1, 2)}`,
2175
- `${R("deleteMany")} ${j("DeleteMany")}:`,
2176
- { model: d, where: h }
2177
- );
2178
- const b = await E.deleteMany({
2179
- model: d,
2180
- where: h
1893
+ l = o(l), a({ method: "deleteMany" }, `${D(h)} ${E(1, 2)}`, `${k("deleteMany")} ${q("DeleteMany")}:`, {
1894
+ model: y,
1895
+ where: p
2181
1896
  });
2182
- return l(
2183
- { method: "deleteMany" },
2184
- `${I(p)} ${T(2, 2)}`,
2185
- `${R("deleteMany")} ${j("DB Result")}:`,
2186
- { model: d, data: b }
2187
- ), b;
1897
+ const N = await Q(`db deleteMany ${y}`, {}, () => C.deleteMany({
1898
+ model: y,
1899
+ where: p
1900
+ }));
1901
+ return a({ method: "deleteMany" }, `${D(h)} ${E(2, 2)}`, `${k("deleteMany")} ${q("DB Result")}:`, {
1902
+ model: y,
1903
+ data: N
1904
+ }), N;
2188
1905
  },
2189
- count: async ({
2190
- model: u,
2191
- where: m
2192
- }) => {
2193
- z++;
2194
- let p = z;
2195
- const d = a(u), h = x({
2196
- model: u,
2197
- where: m
1906
+ count: async ({ model: l, where: b }) => {
1907
+ K++;
1908
+ const h = K, y = d(l), p = P({
1909
+ model: l,
1910
+ where: b,
1911
+ action: "count"
2198
1912
  });
2199
- u = s(u), l(
2200
- { method: "count" },
2201
- `${I(p)} ${T(1, 2)}`,
2202
- `${R("count")}:`,
2203
- {
2204
- model: d,
2205
- where: h
2206
- }
2207
- );
2208
- const b = await E.count({
2209
- model: d,
2210
- where: h
1913
+ l = o(l), a({ method: "count" }, `${D(h)} ${E(1, 2)}`, `${k("count")}:`, {
1914
+ model: y,
1915
+ where: p
2211
1916
  });
2212
- return l(
2213
- { method: "count" },
2214
- `${I(p)} ${T(2, 2)}`,
2215
- `${R("count")}:`,
2216
- {
2217
- model: d,
2218
- data: b
2219
- }
2220
- ), b;
1917
+ const N = await Q(`db count ${y}`, {}, () => C.count({
1918
+ model: y,
1919
+ where: p
1920
+ }));
1921
+ return a({ method: "count" }, `${D(h)} ${E(2, 2)}`, `${k("count")}:`, {
1922
+ model: y,
1923
+ data: N
1924
+ }), N;
2221
1925
  },
2222
- createSchema: E.createSchema ? async (u, m) => {
2223
- const p = De(n);
2224
- return n.secondaryStorage && !n.session?.storeSessionInDatabase && delete p.session, n.rateLimit && n.rateLimit.storage === "database" && // rate-limit will default to enabled in production,
2225
- // and given storage is database, it will try to use the rate-limit table,
2226
- // so we should make sure to generate rate-limit table schema
2227
- (typeof n.rateLimit.enabled > "u" || // and of course if they forcefully set to true, then they want rate-limit,
2228
- // thus we should also generate rate-limit table schema
2229
- n.rateLimit.enabled === !0) && (p.ratelimit = {
2230
- modelName: n.rateLimit.modelName ?? "ratelimit",
2231
- fields: {
2232
- key: {
2233
- type: "string",
2234
- unique: !0,
2235
- required: !0,
2236
- fieldName: n.rateLimit.fields?.key ?? "key"
2237
- },
2238
- count: {
2239
- type: "number",
2240
- required: !0,
2241
- fieldName: n.rateLimit.fields?.count ?? "count"
2242
- },
2243
- lastRequest: {
2244
- type: "number",
2245
- required: !0,
2246
- bigint: !0,
2247
- defaultValue: () => Date.now(),
2248
- fieldName: n.rateLimit.fields?.lastRequest ?? "lastRequest"
2249
- }
2250
- }
2251
- }), E.createSchema({ file: m, tables: p });
1926
+ createSchema: C.createSchema ? async (l, b) => {
1927
+ const h = Ge(n);
1928
+ return n.secondaryStorage && !n.session?.storeSessionInDatabase && delete h.session, C.createSchema({
1929
+ file: b,
1930
+ tables: h
1931
+ });
2252
1932
  } : void 0,
2253
1933
  options: {
2254
- adapterConfig: i,
2255
- ...E.options ?? {}
1934
+ adapterConfig: r,
1935
+ ...C.options ?? {}
2256
1936
  },
2257
- id: i.adapterId,
2258
- // Secretly export values ONLY if this adapter has enabled adapter-test-debug-logs.
2259
- // This would then be used during our adapter-tests to help print debug logs if a test fails.
2260
- //@ts-expect-error - ^^
2261
- ...i.debugLogs?.isRunningAdapterTests ? {
2262
- adapterTestDebugLogs: {
2263
- resetDebugLogs() {
2264
- fe = fe.filter(
2265
- (u) => u.instance !== r
2266
- );
2267
- },
2268
- printDebugLogs() {
2269
- const u = "─".repeat(80), m = fe.filter(
2270
- (d) => d.instance === r
2271
- );
2272
- if (m.length === 0)
2273
- return;
2274
- let p = m.reverse().map((d) => (d.args[0] = `
2275
- ${d.args[0]}`, [...d.args, `
2276
- `])).reduce(
2277
- (d, h) => [...h, ...d],
2278
- [`
2279
- ${u}`]
2280
- );
2281
- console.log(...p);
2282
- }
1937
+ id: r.adapterId,
1938
+ ...r.debugLogs?.isRunningAdapterTests ? { adapterTestDebugLogs: {
1939
+ resetDebugLogs() {
1940
+ ge = ge.filter((l) => l.instance !== i);
1941
+ },
1942
+ printDebugLogs() {
1943
+ const l = "─".repeat(80), b = ge.filter((y) => y.instance === i);
1944
+ if (b.length === 0) return;
1945
+ const h = b.reverse().map((y) => (y.args[0] = `
1946
+ ${y.args[0]}`, [...y.args, `
1947
+ `])).reduce((y, p) => [...p, ...y], [`
1948
+ ${l}`]);
1949
+ console.log(...h);
2283
1950
  }
2284
- } : {}
1951
+ } } : {}
2285
1952
  };
2286
- return V;
1953
+ return Ve;
2287
1954
  };
2288
- function I(e) {
2289
- return Ke() < 8 ? `#${e}` : `${D.fg.magenta}#${e}${D.reset}`;
1955
+ function D(e) {
1956
+ return it() < 8 ? `#${e}` : `${U.fg.magenta}#${e}${U.reset}`;
2290
1957
  }
2291
- function T(e, t) {
2292
- return `${D.bg.black}${D.fg.yellow}[${e}/${t}]${D.reset}`;
1958
+ function E(e, t) {
1959
+ return `${U.bg.black}${U.fg.yellow}[${e}/${t}]${U.reset}`;
2293
1960
  }
2294
- function R(e) {
2295
- return `${D.bright}${e}${D.reset}`;
1961
+ function k(e) {
1962
+ return `${U.bright}${e}${U.reset}`;
2296
1963
  }
2297
- function j(e) {
2298
- return `${D.dim}(${e})${D.reset}`;
1964
+ function q(e) {
1965
+ return `${U.dim}(${e})${U.reset}`;
2299
1966
  }
2300
- const Rn = {};
2301
- function ue(e) {
2302
- return Rn.inspect(e, { colors: !0, depth: null });
1967
+ function he(e) {
1968
+ if (typeof process < "u" && process.versions?.node && typeof require < "u")
1969
+ try {
1970
+ const { inspect: t } = require("node:util");
1971
+ return t(e, { colors: !0, depth: null });
1972
+ } catch {
1973
+ }
1974
+ return JSON.stringify(e, null, 2);
2303
1975
  }
2304
- function Ye(e, t) {
1976
+ function ct(e, t) {
2305
1977
  return e.toLowerCase().endsWith("id") ? e.slice(0, -2) : t;
2306
1978
  }
2307
- function En(e, t, n) {
2308
- const { type: r, required: i, unique: o, sortable: f } = e, s = Array.isArray(r) ? r[0] : r;
2309
- let a;
2310
- switch (s) {
1979
+ function Zt(e, t, n) {
1980
+ const { type: i, required: r, unique: s, sortable: a } = e, u = Array.isArray(i) ? i[0] : i;
1981
+ let o;
1982
+ switch (u) {
2311
1983
  case "string":
2312
- a = "i.string()";
1984
+ o = "i.string()";
2313
1985
  break;
2314
1986
  case "boolean":
2315
- a = "i.boolean()";
1987
+ o = "i.boolean()";
2316
1988
  break;
2317
1989
  case "date":
2318
- a = "i.date()";
1990
+ o = "i.date()";
2319
1991
  break;
2320
1992
  case "number":
2321
- a = "i.number()";
1993
+ o = "i.number()";
2322
1994
  break;
2323
1995
  case "json":
2324
- a = "i.json()";
1996
+ o = "i.json()";
2325
1997
  break;
2326
1998
  case "number[]":
2327
- a = "i.json()";
1999
+ o = "i.json()";
2328
2000
  break;
2329
2001
  case "string[]":
2330
- a = "i.json()";
2002
+ o = "i.json()";
2331
2003
  break;
2332
2004
  default:
2333
- a = "i.string()";
2005
+ o = "i.string()";
2334
2006
  }
2335
- return o && (a += ".unique()"), i === !1 && (a += ".optional()"), f && (a += ".indexed()"), t === "user" && n !== "email" && !a.endsWith(".optional()") && (a += ".optional()"), a;
2007
+ return s && (o += ".unique()"), r === !1 && (o += ".optional()"), a && (o += ".indexed()"), t === "user" && n !== "email" && !o.endsWith(".optional()") && (o += ".optional()"), o;
2336
2008
  }
2337
- function Ce(e, t, n) {
2009
+ function Ye(e, t, n) {
2338
2010
  return e === "user" ? "$users" : n ? `${t}s` : t;
2339
2011
  }
2340
- function Mn(e) {
2012
+ function Qt(e) {
2341
2013
  return e.charAt(0).toLowerCase() + e.slice(1);
2342
2014
  }
2343
- function xn(e, t) {
2344
- const n = {}, r = {};
2345
- for (const [i, o] of Object.entries(e)) {
2346
- const { modelName: f } = o;
2347
- r[f] = Ce(f, i, t);
2015
+ function en(e, t) {
2016
+ const n = {}, i = {};
2017
+ for (const [r, s] of Object.entries(e)) {
2018
+ const { modelName: a } = s;
2019
+ i[a] = Ye(a, r, t);
2348
2020
  }
2349
- for (const [i, o] of Object.entries(e)) {
2350
- const { modelName: f, fields: s } = o, a = Ce(f, i, t);
2351
- for (const [c, l] of Object.entries(s)) {
2352
- const { references: y } = l;
2353
- if (y) {
2354
- const { model: w, onDelete: S } = y, C = r[w];
2355
- if (!C) {
2021
+ for (const [r, s] of Object.entries(e)) {
2022
+ const { modelName: a, fields: u } = s, o = Ye(a, r, t);
2023
+ for (const [c, d] of Object.entries(u)) {
2024
+ const { references: f } = d;
2025
+ if (f) {
2026
+ const { model: g, onDelete: $ } = f, v = i[g];
2027
+ if (!v) {
2356
2028
  console.warn(
2357
- `Warning: Could not find entity name for model "${w}" referenced by ${f}.${c}`
2029
+ `Warning: Could not find entity name for model "${g}" referenced by ${a}.${c}`
2358
2030
  );
2359
2031
  continue;
2360
2032
  }
2361
- const x = Ye(c, w), E = a.replace("$", ""), B = x.charAt(0).toUpperCase() + Mn(x.slice(1)), V = `${E}${B}`, u = a.replace("$", "");
2362
- n[V] = {
2033
+ const j = ct(c, g), P = o.replace("$", ""), X = j.charAt(0).toUpperCase() + Qt(j.slice(1)), H = `${P}${X}`, C = o.replace("$", "");
2034
+ n[H] = {
2363
2035
  forward: {
2364
- on: a,
2036
+ on: o,
2365
2037
  has: "one",
2366
- label: x,
2367
- onDelete: S || "cascade"
2038
+ label: j,
2039
+ onDelete: $ || "cascade"
2368
2040
  },
2369
2041
  reverse: {
2370
- on: C,
2042
+ on: v,
2371
2043
  has: "many",
2372
- label: u
2044
+ label: C
2373
2045
  }
2374
2046
  };
2375
2047
  }
@@ -2377,24 +2049,24 @@ function xn(e, t) {
2377
2049
  }
2378
2050
  return n;
2379
2051
  }
2380
- function jn(e, t) {
2052
+ function tn(e, t) {
2381
2053
  const n = {};
2382
- for (const [s, a] of Object.entries(e)) {
2383
- const { modelName: c, fields: l } = a, y = [];
2384
- for (const [S, C] of Object.entries(l)) {
2385
- const x = En(C, c, S);
2386
- y.push(`${S}: ${x}`);
2054
+ for (const [u, o] of Object.entries(e)) {
2055
+ const { modelName: c, fields: d } = o, f = [];
2056
+ for (const [$, v] of Object.entries(d)) {
2057
+ const j = Zt(v, c, $);
2058
+ f.push(`${$}: ${j}`);
2387
2059
  }
2388
- const w = c === "user" ? "$users" : t ? `${s}s` : s;
2389
- n[w] = `i.entity({
2390
- ${y.join(`,
2060
+ const g = c === "user" ? "$users" : t ? `${u}s` : u;
2061
+ n[g] = `i.entity({
2062
+ ${f.join(`,
2391
2063
  `)}
2392
2064
  })`;
2393
2065
  }
2394
- const r = xn(e, t), i = Object.entries(n).map(([s, a]) => ` ${s}: ${a}`).join(`,
2395
- `), o = Object.entries(r).map(([s, a]) => {
2396
- const c = a.forward, l = a.reverse;
2397
- return ` ${s}: {
2066
+ const i = en(e, t), r = Object.entries(n).map(([u, o]) => ` ${u}: ${o}`).join(`,
2067
+ `), s = Object.entries(i).map(([u, o]) => {
2068
+ const c = o.forward, d = o.reverse;
2069
+ return ` ${u}: {
2398
2070
  forward: {
2399
2071
  on: "${c.on}",
2400
2072
  has: "${c.has}",
@@ -2402,15 +2074,15 @@ function jn(e, t) {
2402
2074
  onDelete: "${c.onDelete}"` : ""}
2403
2075
  },
2404
2076
  reverse: {
2405
- on: "${l.on}",
2406
- has: "${l.has}",
2407
- label: "${l.label}"
2077
+ on: "${d.on}",
2078
+ has: "${d.has}",
2079
+ label: "${d.label}"
2408
2080
  }
2409
2081
  }`;
2410
2082
  }).join(`,
2411
- `), f = o ? `,
2083
+ `), a = s ? `,
2412
2084
  links: {
2413
- ${o}
2085
+ ${s}
2414
2086
  }` : "";
2415
2087
  return `// Docs: https://www.instantdb.com/docs/modeling-data
2416
2088
 
@@ -2418,204 +2090,226 @@ import { i } from "@instantdb/react"
2418
2090
 
2419
2091
  export const authSchema = i.schema({
2420
2092
  entities: {
2421
- ${i}
2422
- }${f}
2093
+ ${r}
2094
+ }${a}
2423
2095
  })
2424
2096
  `;
2425
2097
  }
2426
- function kn(e, t, n) {
2098
+ function nn(e, t, n) {
2427
2099
  return e === "user" ? "$users" : n ? `${t}s` : t;
2428
2100
  }
2429
- function Dn(e, t) {
2101
+ function rn(e, t) {
2430
2102
  const n = {};
2431
- for (const [r, i] of Object.entries(e)) {
2432
- const { modelName: o } = i;
2433
- n[o] = kn(o, r, t);
2103
+ for (const [i, r] of Object.entries(e)) {
2104
+ const { modelName: s } = r;
2105
+ n[s] = nn(s, i, t);
2434
2106
  }
2435
2107
  return n;
2436
2108
  }
2437
- function Ln({
2109
+ function on({
2438
2110
  db: e,
2439
2111
  model: t,
2440
2112
  modelSchema: n,
2441
- data: r,
2442
- entityNameMap: i
2113
+ data: i,
2114
+ entityNameMap: r
2443
2115
  }) {
2444
- const o = [], { fields: f, modelName: s } = n;
2445
- for (const [a, c] of Object.entries(f)) {
2446
- const { references: l } = c;
2447
- if (l) {
2448
- const { model: y } = l;
2449
- if (!i[y]) {
2116
+ const s = [], { fields: a, modelName: u } = n;
2117
+ for (const [o, c] of Object.entries(a)) {
2118
+ const { references: d } = c;
2119
+ if (d) {
2120
+ const { model: f } = d;
2121
+ if (!r[f]) {
2450
2122
  console.warn(
2451
- `Warning: Could not find entity name for model "${y}" referenced by ${s}.${a}`
2123
+ `Warning: Could not find entity name for model "${f}" referenced by ${u}.${o}`
2452
2124
  );
2453
2125
  continue;
2454
2126
  }
2455
- const S = r[a];
2456
- if (S != null) {
2457
- const x = {
2458
- [Ye(a, y)]: S
2459
- }, E = e.tx[t][r.id].link(x);
2460
- o.push(E);
2127
+ const $ = i[o];
2128
+ if ($ != null) {
2129
+ const j = {
2130
+ [ct(o, f)]: $
2131
+ }, P = e.tx[t][i.id].link(j);
2132
+ s.push(P);
2461
2133
  }
2462
2134
  }
2463
2135
  }
2464
- return o;
2136
+ return s;
2465
2137
  }
2466
- const Pn = ({
2138
+ const cn = ({
2467
2139
  db: e,
2468
2140
  usePlural: t = !0,
2469
2141
  debugLogs: n = !1
2470
- }) => Tn({
2471
- config: {
2472
- customIdGenerator: mt,
2473
- adapterId: "instantdb-adapter",
2474
- // A unique identifier for the adapter.
2475
- adapterName: "InstantDB Adapter",
2476
- // The name of the adapter.
2477
- usePlural: t,
2478
- // Whether the table names in the schema are plural.
2479
- debugLogs: n,
2480
- // Whether to enable debug logs.
2481
- supportsJSON: !0,
2482
- // Whether the database supports JSON. (Default: false)
2483
- supportsDates: !1,
2484
- // Whether the database supports dates. (Default: true)
2485
- supportsBooleans: !0,
2486
- // Whether the database supports booleans. (Default: true)
2487
- supportsNumericIds: !1
2488
- // Whether the database supports auto-incrementing numeric IDs. (Default: true)
2489
- },
2490
- adapter: ({ debugLog: r, getDefaultModelName: i, getFieldName: o, schema: f }) => ({
2491
- create: async ({ data: s, model: a }) => {
2492
- const c = i(a), l = f[c];
2493
- if (c === "session") {
2494
- const E = (await e.query({
2495
- $users: { $: { where: { id: s.userId } } }
2496
- })).$users;
2497
- if (!E.length)
2498
- throw new Error(`$users entity not found: ${s.userId}`);
2499
- const B = E[0];
2500
- r("Create Token", B.email);
2501
- const V = await e.auth.createToken(B.email), u = o({ model: a, field: "token" });
2502
- Object.assign(s, { [u]: V });
2503
- }
2504
- c === "user" && (a = "$users"), r("Create", a, ue(s));
2505
- const y = Dn(f, t), w = e.tx[a][s.id].create(s), S = Ln({
2506
- db: e,
2507
- model: a,
2508
- modelSchema: l,
2509
- data: s,
2510
- entityNameMap: y
2511
- }), C = [w, ...S];
2512
- return await e.transact(C), s;
2513
- },
2514
- update: async ({ update: s, model: a, where: c }) => {
2515
- i(a) === "user" && (a = "$users");
2516
- const l = await J({ db: e, model: a, where: c, debugLog: r });
2517
- if (!l.length) return null;
2518
- r(
2519
- "Update:",
2520
- l.map((w) => w.id),
2521
- ue(s)
2522
- );
2523
- const y = l.map(
2524
- (w) => e.tx[a][w.id].update(s)
2525
- );
2526
- return await e.transact(y), { ...l[0], ...s };
2527
- },
2528
- updateMany: async ({ update: s, model: a, where: c }) => {
2529
- i(a) === "user" && (a = "$users");
2530
- const l = await J({ db: e, model: a, where: c, debugLog: r });
2531
- if (!l.length) return 0;
2532
- r(
2533
- "Update:",
2534
- l.map((w) => w.id),
2535
- ue(s)
2536
- );
2537
- const y = l.map(
2538
- (w) => e.tx[a][w.id].update(s)
2539
- );
2540
- return await e.transact(y), l.length;
2142
+ }) => {
2143
+ const i = Xt({
2144
+ config: {
2145
+ customIdGenerator: St,
2146
+ adapterId: "instantdb-adapter",
2147
+ // A unique identifier for the adapter.
2148
+ adapterName: "InstantDB Adapter",
2149
+ // The name of the adapter.
2150
+ usePlural: t,
2151
+ // Whether the table names in the schema are plural.
2152
+ debugLogs: n,
2153
+ // Whether to enable debug logs.
2154
+ supportsJSON: !0,
2155
+ // Whether the database supports JSON. (Default: false)
2156
+ supportsDates: !1,
2157
+ // Whether the database supports dates. (Default: true)
2158
+ supportsBooleans: !0,
2159
+ // Whether the database supports booleans. (Default: true)
2160
+ supportsNumericIds: !1
2161
+ // Whether the database supports auto-incrementing numeric IDs. (Default: true)
2541
2162
  },
2542
- delete: async ({ model: s, where: a }) => {
2543
- i(s) === "user" && (s = "$users");
2544
- const c = await J({ db: e, model: s, where: a, debugLog: r });
2545
- if (!c.length) return;
2546
- const l = c.map(
2547
- (y) => e.tx[s][y.id].delete()
2548
- );
2549
- await e.transact(l), i(s) === "session" && Promise.all(
2550
- c.map(async (y) => {
2551
- try {
2552
- const w = o({ model: s, field: "token" });
2553
- await e.auth.signOut({
2554
- refresh_token: y[w]
2555
- });
2556
- } catch {
2557
- }
2558
- })
2559
- );
2560
- },
2561
- deleteMany: async ({ model: s, where: a }) => {
2562
- i(s) === "user" && (s = "$users");
2563
- const c = await J({ db: e, model: s, where: a, debugLog: r });
2564
- if (!c.length) return 0;
2565
- const l = c.map(
2566
- (y) => e.tx[s][y.id].delete()
2567
- );
2568
- return await e.transact(l), i(s) === "session" && Promise.all(
2569
- c.map(async (y) => {
2570
- try {
2571
- const w = o({ model: s, field: "token" });
2572
- await e.auth.signOut({
2573
- refresh_token: y[w]
2574
- });
2575
- } catch {
2576
- }
2577
- })
2578
- ), c.length;
2579
- },
2580
- findOne: async ({ model: s, where: a }) => {
2581
- i(s) === "user" && (s = "$users");
2582
- const c = await J({ db: e, model: s, where: a, debugLog: r });
2583
- return c.length ? c[0] : null;
2584
- },
2585
- findMany: async ({ model: s, where: a, limit: c, sortBy: l, offset: y }) => (i(s) === "user" && (s = "$users"), await J({
2586
- db: e,
2587
- model: s,
2588
- where: a,
2589
- limit: c,
2590
- sortBy: l,
2591
- offset: y,
2592
- debugLog: r
2593
- })),
2594
- count: async ({ model: s, where: a }) => (i(s) === "user" && (s = "$users"), (await J({ db: e, model: s, where: a, debugLog: r })).length),
2595
- createSchema: async ({ file: s = "./auth.schema.ts", tables: a }) => ({ code: jn(a, t), path: s })
2596
- })
2597
- });
2598
- async function J({
2163
+ adapter: ({ debugLog: r, getDefaultModelName: s, getFieldName: a, schema: u }) => ({
2164
+ create: async ({ data: o, model: c }) => {
2165
+ const d = s(c), f = u[d];
2166
+ if (d === "session") {
2167
+ const X = (await e.query({
2168
+ $users: { $: { where: { id: o.userId } } }
2169
+ })).$users;
2170
+ if (!X.length)
2171
+ throw new Error(`$users entity not found: ${o.userId}`);
2172
+ const H = X[0];
2173
+ r("Create Token", H.email);
2174
+ const C = await e.auth.createToken(H.email), ue = a({ model: c, field: "token" });
2175
+ Object.assign(o, { [ue]: C });
2176
+ }
2177
+ d === "user" && (c = "$users"), r("Create", c, he(o));
2178
+ const g = rn(u, t), $ = e.tx[c][o.id].create(o), v = on({
2179
+ db: e,
2180
+ model: c,
2181
+ modelSchema: f,
2182
+ data: o,
2183
+ entityNameMap: g
2184
+ }), j = [$, ...v];
2185
+ return await e.transact(j), o;
2186
+ },
2187
+ update: async ({ update: o, model: c, where: d }) => {
2188
+ s(c) === "user" && (c = "$users");
2189
+ const f = await oe({ db: e, model: c, where: d, debugLog: r });
2190
+ if (!f.length) return null;
2191
+ r(
2192
+ "Update:",
2193
+ f.map(($) => $.id),
2194
+ he(o)
2195
+ );
2196
+ const g = f.map(
2197
+ ($) => e.tx[c][$.id].update(o)
2198
+ );
2199
+ return await e.transact(g), { ...f[0], ...o };
2200
+ },
2201
+ updateMany: async ({ update: o, model: c, where: d }) => {
2202
+ s(c) === "user" && (c = "$users");
2203
+ const f = await oe({ db: e, model: c, where: d, debugLog: r });
2204
+ if (!f.length) return 0;
2205
+ r(
2206
+ "Update:",
2207
+ f.map(($) => $.id),
2208
+ he(o)
2209
+ );
2210
+ const g = f.map(
2211
+ ($) => e.tx[c][$.id].update(o)
2212
+ );
2213
+ return await e.transact(g), f.length;
2214
+ },
2215
+ delete: async ({ model: o, where: c }) => {
2216
+ s(o) === "user" && (o = "$users");
2217
+ const d = await oe({ db: e, model: o, where: c, debugLog: r });
2218
+ if (!d.length) return;
2219
+ const f = d.map(
2220
+ (g) => e.tx[o][g.id].delete()
2221
+ );
2222
+ await e.transact(f), s(o) === "session" && Promise.all(
2223
+ d.map(async (g) => {
2224
+ try {
2225
+ const $ = a({ model: o, field: "token" });
2226
+ await e.auth.signOut({
2227
+ refresh_token: g[$]
2228
+ });
2229
+ } catch {
2230
+ }
2231
+ })
2232
+ );
2233
+ },
2234
+ deleteMany: async ({ model: o, where: c }) => {
2235
+ s(o) === "user" && (o = "$users");
2236
+ const d = await oe({ db: e, model: o, where: c, debugLog: r });
2237
+ if (!d.length) return 0;
2238
+ const f = d.map(
2239
+ (g) => e.tx[o][g.id].delete()
2240
+ );
2241
+ return await e.transact(f), s(o) === "session" && Promise.all(
2242
+ d.map(async (g) => {
2243
+ try {
2244
+ const $ = a({ model: o, field: "token" });
2245
+ await e.auth.signOut({
2246
+ refresh_token: g[$]
2247
+ });
2248
+ } catch {
2249
+ }
2250
+ })
2251
+ ), d.length;
2252
+ },
2253
+ findOne: async ({ model: o, where: c }) => {
2254
+ s(o) === "user" && (o = "$users");
2255
+ const d = await oe({ db: e, model: o, where: c, debugLog: r });
2256
+ return d.length ? d[0] : null;
2257
+ },
2258
+ findMany: async ({ model: o, where: c, limit: d, sortBy: f, offset: g }) => (s(o) === "user" && (o = "$users"), await oe({
2259
+ db: e,
2260
+ model: o,
2261
+ where: c,
2262
+ limit: d,
2263
+ sortBy: f,
2264
+ offset: g,
2265
+ debugLog: r
2266
+ })),
2267
+ count: async ({ model: o, where: c }) => (s(o) === "user" && (o = "$users"), (await oe({ db: e, model: o, where: c, debugLog: r })).length),
2268
+ createSchema: async ({ file: o = "./auth.schema.ts", tables: c }) => ({ code: tn(c, t), path: o })
2269
+ })
2270
+ });
2271
+ return ((r) => {
2272
+ const s = i(r), a = s.findOne.bind(s);
2273
+ return {
2274
+ ...s,
2275
+ findOne: async (u) => {
2276
+ const o = await a(u);
2277
+ if (u.model === "session" && u.join?.user && o && !o.user && o.userId) {
2278
+ const c = await a({
2279
+ model: "user",
2280
+ where: [{ field: "id", value: o.userId }]
2281
+ });
2282
+ return {
2283
+ ...o,
2284
+ user: c
2285
+ };
2286
+ }
2287
+ return o;
2288
+ }
2289
+ };
2290
+ });
2291
+ };
2292
+ async function oe({
2599
2293
  db: e,
2600
2294
  debugLog: t,
2601
2295
  model: n,
2602
- where: r,
2603
- limit: i,
2604
- offset: o,
2605
- sortBy: f
2296
+ where: i,
2297
+ limit: r,
2298
+ offset: s,
2299
+ sortBy: a
2606
2300
  }) {
2607
- let s;
2608
- f && (s = {
2609
- [f.field]: f.direction
2301
+ let u;
2302
+ a && (u = {
2303
+ [a.field]: a.direction
2610
2304
  });
2611
- const a = {
2612
- [n]: { $: { where: Cn(r), limit: i, offset: o, order: s } }
2305
+ const o = {
2306
+ [n]: { $: { where: sn(i), limit: r, offset: s, order: u } }
2613
2307
  };
2614
- t("Query", ue(a));
2615
- const c = await e.query(a);
2616
- return t("Result", ue(c)), c[n];
2308
+ t("Query", he(o));
2309
+ const c = await e.query(o);
2310
+ return t("Result", he(c)), c[n];
2617
2311
  }
2618
- function Cn(e) {
2312
+ function sn(e) {
2619
2313
  const t = {};
2620
2314
  return e?.forEach((n) => {
2621
2315
  switch (n.operator) {
@@ -2652,12 +2346,12 @@ function Cn(e) {
2652
2346
  }
2653
2347
  }), t;
2654
2348
  }
2655
- async function zn(e, t) {
2349
+ async function un(e, t) {
2656
2350
  const n = await e.getAuth();
2657
2351
  t && n?.id !== t?.userId && e.auth.signInWithToken(t.token), !t && n && e.auth.signOut();
2658
2352
  }
2659
2353
  export {
2660
- Pn as instantAdapter,
2661
- zn as instantAuth,
2662
- Cn as parseWhere
2354
+ cn as instantAdapter,
2355
+ un as instantAuth,
2356
+ sn as parseWhere
2663
2357
  };