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/adapter/instant-adapter.d.ts +2 -2
- package/dist/index.cjs +19 -17
- package/dist/index.js +1554 -1860
- package/dist/lib/utils.d.ts +2 -3
- package/dist/react/use-instant-session.d.ts +5 -5
- package/dist/react/use-persistent-session.d.ts +5 -5
- package/package.json +4 -4
- package/src/adapter/instant-adapter.ts +37 -1
- package/src/lib/utils.ts +24 -8
package/dist/index.js
CHANGED
|
@@ -1,138 +1,138 @@
|
|
|
1
|
-
const
|
|
1
|
+
const V = {
|
|
2
2
|
Remove: "remove",
|
|
3
3
|
Replace: "replace",
|
|
4
4
|
Add: "add"
|
|
5
|
-
},
|
|
5
|
+
}, Xe = /* @__PURE__ */ Symbol.for("__MUTATIVE_PROXY_DRAFT__"), $e = Symbol.iterator, Z = {
|
|
6
6
|
mutable: "mutable",
|
|
7
7
|
immutable: "immutable"
|
|
8
|
-
},
|
|
9
|
-
function
|
|
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
|
|
12
|
+
function Ue(e, t) {
|
|
13
13
|
if (t in e) {
|
|
14
14
|
let n = Reflect.getPrototypeOf(e);
|
|
15
15
|
for (; n; ) {
|
|
16
|
-
const
|
|
17
|
-
if (
|
|
18
|
-
return
|
|
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
|
|
23
|
+
function Ze(e) {
|
|
24
24
|
return Object.getPrototypeOf(e) === Set.prototype;
|
|
25
25
|
}
|
|
26
|
-
function
|
|
26
|
+
function Qe(e) {
|
|
27
27
|
return Object.getPrototypeOf(e) === Map.prototype;
|
|
28
28
|
}
|
|
29
|
-
function
|
|
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
|
|
34
|
-
return !!
|
|
33
|
+
function ve(e) {
|
|
34
|
+
return !!T(e);
|
|
35
35
|
}
|
|
36
|
-
function
|
|
37
|
-
return typeof e != "object" ? null : e?.[
|
|
36
|
+
function T(e) {
|
|
37
|
+
return typeof e != "object" ? null : e?.[Xe];
|
|
38
38
|
}
|
|
39
|
-
function
|
|
39
|
+
function Ce(e) {
|
|
40
40
|
var t;
|
|
41
|
-
const n =
|
|
41
|
+
const n = T(e);
|
|
42
42
|
return n ? (t = n.copy) !== null && t !== void 0 ? t : n.original : e;
|
|
43
43
|
}
|
|
44
|
-
function
|
|
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,
|
|
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
|
|
50
|
+
function et(e, t = []) {
|
|
51
51
|
if (Object.hasOwnProperty.call(e, "key")) {
|
|
52
|
-
const n = e.parent.copy,
|
|
53
|
-
if (
|
|
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
|
|
56
|
-
if (!(
|
|
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(
|
|
58
|
+
t.push(s);
|
|
59
59
|
}
|
|
60
60
|
if (e.parent)
|
|
61
|
-
return
|
|
61
|
+
return et(e.parent, t);
|
|
62
62
|
t.reverse();
|
|
63
63
|
try {
|
|
64
|
-
|
|
64
|
+
dt(e.copy, t);
|
|
65
65
|
} catch {
|
|
66
66
|
return null;
|
|
67
67
|
}
|
|
68
68
|
return t;
|
|
69
69
|
}
|
|
70
|
-
function
|
|
70
|
+
function we(e) {
|
|
71
71
|
return Array.isArray(e) ? 1 : e instanceof Map ? 2 : e instanceof Set ? 3 : 0;
|
|
72
72
|
}
|
|
73
|
-
function
|
|
74
|
-
return
|
|
73
|
+
function ie(e, t) {
|
|
74
|
+
return we(e) === 2 ? e.get(t) : e[t];
|
|
75
75
|
}
|
|
76
|
-
function
|
|
77
|
-
|
|
76
|
+
function Le(e, t, n) {
|
|
77
|
+
we(e) === 2 ? e.set(t, n) : e[t] = n;
|
|
78
78
|
}
|
|
79
|
-
function
|
|
80
|
-
const n =
|
|
81
|
-
return (n ?
|
|
79
|
+
function Se(e, t) {
|
|
80
|
+
const n = T(e);
|
|
81
|
+
return (n ? W(n) : e)[t];
|
|
82
82
|
}
|
|
83
|
-
function
|
|
83
|
+
function ae(e, t) {
|
|
84
84
|
return e === t ? e !== 0 || 1 / e === 1 / t : e !== e && t !== t;
|
|
85
85
|
}
|
|
86
|
-
function
|
|
86
|
+
function se(e, t) {
|
|
87
87
|
return t ? e : [""].concat(e).map((n) => {
|
|
88
|
-
const
|
|
89
|
-
return
|
|
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
|
|
92
|
+
function dt(e, t) {
|
|
93
93
|
for (let n = 0; n < t.length - 1; n += 1) {
|
|
94
|
-
const
|
|
95
|
-
if (e =
|
|
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
|
|
100
|
+
function lt(e) {
|
|
101
101
|
const t = Object.create(Object.getPrototypeOf(e));
|
|
102
102
|
return Reflect.ownKeys(e).forEach((n) => {
|
|
103
|
-
let
|
|
104
|
-
if (
|
|
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
|
-
|
|
108
|
+
i.writable || (i.writable = !0, i.configurable = !0), (i.get || i.set) && (i = {
|
|
109
109
|
configurable: !0,
|
|
110
110
|
writable: !0,
|
|
111
|
-
enumerable:
|
|
111
|
+
enumerable: i.enumerable,
|
|
112
112
|
value: e[n]
|
|
113
|
-
}), Reflect.defineProperty(t, n,
|
|
113
|
+
}), Reflect.defineProperty(t, n, i);
|
|
114
114
|
}), t;
|
|
115
115
|
}
|
|
116
|
-
const
|
|
117
|
-
function
|
|
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 (!
|
|
123
|
-
const
|
|
124
|
-
return new
|
|
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 (!
|
|
129
|
-
const
|
|
130
|
-
return new
|
|
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,
|
|
134
|
-
if (n ===
|
|
135
|
-
return
|
|
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
|
|
144
|
-
return Object.keys(e).forEach((
|
|
145
|
-
r
|
|
146
|
-
}), Object.getOwnPropertySymbols(e).forEach((
|
|
147
|
-
|
|
148
|
-
}),
|
|
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
|
|
153
|
-
e.copy || (e.copy =
|
|
152
|
+
function J(e) {
|
|
153
|
+
e.copy || (e.copy = pt(e.original, e.options));
|
|
154
154
|
}
|
|
155
|
-
function
|
|
156
|
-
if (!
|
|
157
|
-
return
|
|
155
|
+
function me(e) {
|
|
156
|
+
if (!ce(e))
|
|
157
|
+
return Ce(e);
|
|
158
158
|
if (Array.isArray(e))
|
|
159
|
-
return e.map(
|
|
159
|
+
return e.map(me);
|
|
160
160
|
if (e instanceof Map) {
|
|
161
|
-
const n = Array.from(e.entries()).map(([
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
const n = Array.from(e.entries()).map(([i, r]) => [
|
|
162
|
+
i,
|
|
163
|
+
me(r)
|
|
164
164
|
]);
|
|
165
|
-
if (!
|
|
166
|
-
const
|
|
167
|
-
return new
|
|
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(
|
|
173
|
-
if (!
|
|
174
|
-
const
|
|
175
|
-
return new
|
|
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] =
|
|
181
|
+
t[n] = me(e[n]);
|
|
182
182
|
return t;
|
|
183
183
|
}
|
|
184
|
-
function
|
|
185
|
-
return
|
|
184
|
+
function Oe(e) {
|
|
185
|
+
return ve(e) ? me(e) : e;
|
|
186
186
|
}
|
|
187
|
-
function
|
|
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 &&
|
|
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
|
|
192
|
-
const n =
|
|
191
|
+
function mt(e, t) {
|
|
192
|
+
const n = we(e);
|
|
193
193
|
if (n === 0)
|
|
194
|
-
Reflect.ownKeys(e).forEach((
|
|
195
|
-
t(
|
|
194
|
+
Reflect.ownKeys(e).forEach((i) => {
|
|
195
|
+
t(i, e[i], e);
|
|
196
196
|
});
|
|
197
197
|
else if (n === 1) {
|
|
198
|
-
let
|
|
199
|
-
for (const
|
|
200
|
-
t(
|
|
198
|
+
let i = 0;
|
|
199
|
+
for (const r of e)
|
|
200
|
+
t(i, r, e), i += 1;
|
|
201
201
|
} else
|
|
202
|
-
e.forEach((
|
|
202
|
+
e.forEach((i, r) => t(r, i, e));
|
|
203
203
|
}
|
|
204
|
-
function
|
|
205
|
-
if (
|
|
204
|
+
function tt(e, t, n) {
|
|
205
|
+
if (ve(e) || !ce(e, n) || t.has(e) || Object.isFrozen(e))
|
|
206
206
|
return;
|
|
207
|
-
const
|
|
208
|
-
if (t.add(e),
|
|
209
|
-
var
|
|
210
|
-
if (
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
const c = !((
|
|
214
|
-
|
|
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
|
-
|
|
217
|
-
}),
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
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
|
|
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 &&
|
|
226
|
+
e.finalities.revoke.length > 1 && e.assignedMap.get(t) && n && tt(ie(n, t), e.finalities.handledSet, e.options);
|
|
227
227
|
}
|
|
228
|
-
function
|
|
228
|
+
function Me(e) {
|
|
229
229
|
e.type === 3 && e.copy && (e.copy.clear(), e.setMap.forEach((t) => {
|
|
230
|
-
e.copy.add(
|
|
230
|
+
e.copy.add(Ce(t));
|
|
231
231
|
}));
|
|
232
232
|
}
|
|
233
|
-
function
|
|
233
|
+
function Te(e, t, n, i) {
|
|
234
234
|
if (e.operated && e.assignedMap && e.assignedMap.size > 0 && !e.finalized) {
|
|
235
|
-
if (n &&
|
|
236
|
-
const
|
|
237
|
-
|
|
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
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
var
|
|
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
|
-
|
|
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
|
|
257
|
-
let { original:
|
|
258
|
-
|
|
259
|
-
for (let c = 0; c <
|
|
260
|
-
if (
|
|
261
|
-
const
|
|
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:
|
|
264
|
-
path:
|
|
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:
|
|
267
|
-
}),
|
|
268
|
-
op:
|
|
269
|
-
path:
|
|
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:
|
|
271
|
+
value: Oe(s[c])
|
|
272
272
|
});
|
|
273
273
|
}
|
|
274
|
-
for (let c =
|
|
275
|
-
const
|
|
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:
|
|
278
|
-
path:
|
|
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:
|
|
280
|
+
value: Oe(o[c])
|
|
281
281
|
});
|
|
282
282
|
}
|
|
283
|
-
if (
|
|
284
|
-
const { arrayLengthAssignment: c = !0 } =
|
|
283
|
+
if (s.length < o.length) {
|
|
284
|
+
const { arrayLengthAssignment: c = !0 } = u.enablePatches;
|
|
285
285
|
if (c) {
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
op:
|
|
289
|
-
path:
|
|
290
|
-
value:
|
|
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
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
op:
|
|
297
|
-
path:
|
|
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
|
|
303
|
-
n.forEach((
|
|
304
|
-
const c =
|
|
305
|
-
if (
|
|
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
|
|
308
|
-
|
|
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
|
|
312
|
-
let
|
|
313
|
-
e.forEach((
|
|
314
|
-
if (!t.has(
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
op:
|
|
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:
|
|
320
|
-
}),
|
|
321
|
-
op:
|
|
319
|
+
value: u
|
|
320
|
+
}), r.unshift({
|
|
321
|
+
op: V.Add,
|
|
322
322
|
path: c,
|
|
323
|
-
value:
|
|
323
|
+
value: u
|
|
324
324
|
});
|
|
325
325
|
}
|
|
326
|
-
|
|
327
|
-
}),
|
|
328
|
-
if (!e.has(
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
op:
|
|
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:
|
|
334
|
-
}),
|
|
335
|
-
op:
|
|
333
|
+
value: u
|
|
334
|
+
}), r.unshift({
|
|
335
|
+
op: V.Remove,
|
|
336
336
|
path: c,
|
|
337
|
-
value:
|
|
337
|
+
value: u
|
|
338
338
|
});
|
|
339
339
|
}
|
|
340
|
-
|
|
340
|
+
a += 1;
|
|
341
341
|
});
|
|
342
342
|
}
|
|
343
|
-
function
|
|
344
|
-
const { pathAsArray:
|
|
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
|
|
348
|
+
return bt(e, t, n, i, r);
|
|
349
349
|
case 1:
|
|
350
|
-
return
|
|
350
|
+
return ht(e, t, n, i, r);
|
|
351
351
|
case 3:
|
|
352
|
-
return
|
|
352
|
+
return wt(e, t, n, i, r);
|
|
353
353
|
}
|
|
354
354
|
}
|
|
355
|
-
const
|
|
356
|
-
if (typeof e == "object" && e !== null && (!
|
|
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
|
-
},
|
|
358
|
+
}, je = {
|
|
359
359
|
get size() {
|
|
360
|
-
return
|
|
360
|
+
return W(T(this)).size;
|
|
361
361
|
},
|
|
362
362
|
has(e) {
|
|
363
|
-
return
|
|
363
|
+
return W(T(this)).has(e);
|
|
364
364
|
},
|
|
365
365
|
set(e, t) {
|
|
366
|
-
const n =
|
|
367
|
-
return (!
|
|
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 =
|
|
373
|
-
return
|
|
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 =
|
|
376
|
+
const e = T(this);
|
|
377
377
|
if (this.size) {
|
|
378
|
-
|
|
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 =
|
|
386
|
-
|
|
387
|
-
e.call(t, this.get(
|
|
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
|
|
393
|
-
if (
|
|
394
|
-
return
|
|
395
|
-
const
|
|
396
|
-
original:
|
|
397
|
-
parentDraft:
|
|
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:
|
|
400
|
-
options:
|
|
399
|
+
finalities: i.finalities,
|
|
400
|
+
options: i.options
|
|
401
401
|
});
|
|
402
|
-
return
|
|
402
|
+
return J(i), i.copy.set(e, a), a;
|
|
403
403
|
},
|
|
404
404
|
keys() {
|
|
405
|
-
return
|
|
405
|
+
return W(T(this)).keys();
|
|
406
406
|
},
|
|
407
407
|
values() {
|
|
408
408
|
const e = this.keys();
|
|
409
409
|
return {
|
|
410
|
-
[
|
|
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
|
-
[
|
|
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
|
-
[
|
|
436
|
+
[$e]() {
|
|
437
437
|
return this.entries();
|
|
438
438
|
}
|
|
439
|
-
},
|
|
440
|
-
var
|
|
441
|
-
const
|
|
442
|
-
if (
|
|
443
|
-
return
|
|
444
|
-
const
|
|
445
|
-
let
|
|
446
|
-
const
|
|
447
|
-
if (e.options.strict &&
|
|
448
|
-
const
|
|
449
|
-
original:
|
|
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:
|
|
451
|
+
key: a,
|
|
452
452
|
finalities: e.finalities,
|
|
453
453
|
options: e.options
|
|
454
454
|
});
|
|
455
|
-
e.setMap.set(
|
|
456
|
-
} else
|
|
455
|
+
e.setMap.set(a, d), u = d;
|
|
456
|
+
} else o && (u = o.proxy);
|
|
457
457
|
return {
|
|
458
458
|
done: !1,
|
|
459
|
-
value: n ?
|
|
459
|
+
value: n ? u : [u, u]
|
|
460
460
|
};
|
|
461
|
-
},
|
|
461
|
+
}, Ae = {
|
|
462
462
|
get size() {
|
|
463
|
-
return
|
|
463
|
+
return T(this).setMap.size;
|
|
464
464
|
},
|
|
465
465
|
has(e) {
|
|
466
|
-
const t =
|
|
466
|
+
const t = T(this);
|
|
467
467
|
if (t.setMap.has(e))
|
|
468
468
|
return !0;
|
|
469
|
-
|
|
470
|
-
const n =
|
|
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 =
|
|
475
|
-
return this.has(e) || (
|
|
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 =
|
|
481
|
-
|
|
482
|
-
const n =
|
|
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 =
|
|
489
|
-
|
|
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 =
|
|
496
|
-
|
|
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:
|
|
500
|
+
next: Pe(e, t, { isValuesIterator: !0 })
|
|
501
501
|
};
|
|
502
502
|
},
|
|
503
503
|
entries() {
|
|
504
|
-
const e =
|
|
505
|
-
|
|
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:
|
|
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
|
-
[
|
|
517
|
+
[$e]() {
|
|
518
518
|
return this.values();
|
|
519
519
|
},
|
|
520
520
|
forEach(e, t) {
|
|
521
521
|
const n = this.values();
|
|
522
|
-
let
|
|
523
|
-
for (; !
|
|
524
|
-
e.call(t,
|
|
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(
|
|
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
|
|
550
|
+
const $t = Reflect.ownKeys(Ae), nt = {
|
|
551
551
|
get(e, t, n) {
|
|
552
|
-
var
|
|
553
|
-
const
|
|
554
|
-
if (
|
|
555
|
-
return
|
|
556
|
-
if (t ===
|
|
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
|
|
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 (
|
|
562
|
-
return e.options.strict &&
|
|
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
|
|
565
|
-
if (
|
|
566
|
-
return t === "size" ? Object.getOwnPropertyDescriptor(
|
|
567
|
-
if (
|
|
568
|
-
return t === "size" ? Object.getOwnPropertyDescriptor(
|
|
569
|
-
if (!
|
|
570
|
-
const c =
|
|
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
|
-
(
|
|
573
|
+
(r = c.get) === null || r === void 0 ? void 0 : r.call(e.proxy)
|
|
574
574
|
) : void 0;
|
|
575
575
|
}
|
|
576
|
-
const
|
|
577
|
-
if (e.options.strict &&
|
|
578
|
-
return
|
|
579
|
-
if (
|
|
580
|
-
if (
|
|
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
|
|
587
|
-
const c =
|
|
588
|
-
return
|
|
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
|
|
592
|
+
return ve(o) && e.finalities.draftsCache.add(o), o;
|
|
593
593
|
},
|
|
594
594
|
set(e, t, n) {
|
|
595
|
-
var
|
|
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
|
|
599
|
-
if (e.type === 1 && t !== "length" && !(Number.isInteger(
|
|
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
|
|
602
|
-
if (
|
|
603
|
-
return
|
|
604
|
-
const
|
|
605
|
-
return
|
|
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
|
|
608
|
+
return t in W(e);
|
|
609
609
|
},
|
|
610
610
|
ownKeys(e) {
|
|
611
|
-
return Reflect.ownKeys(
|
|
611
|
+
return Reflect.ownKeys(W(e));
|
|
612
612
|
},
|
|
613
613
|
getOwnPropertyDescriptor(e, t) {
|
|
614
|
-
const n =
|
|
615
|
-
return
|
|
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:
|
|
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 ?
|
|
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
|
|
637
|
-
const { original: t, parentDraft: n, key:
|
|
638
|
-
type:
|
|
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:
|
|
645
|
-
options:
|
|
644
|
+
finalities: r,
|
|
645
|
+
options: s,
|
|
646
646
|
// Mapping of draft Set items to their corresponding draft values.
|
|
647
|
-
setMap:
|
|
647
|
+
setMap: a === 3 ? new Map(t.entries()) : void 0
|
|
648
648
|
};
|
|
649
|
-
(
|
|
650
|
-
const { proxy:
|
|
651
|
-
if (
|
|
652
|
-
const
|
|
653
|
-
|
|
654
|
-
var
|
|
655
|
-
const
|
|
656
|
-
let
|
|
657
|
-
const
|
|
658
|
-
if (
|
|
659
|
-
let
|
|
660
|
-
|
|
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
|
-
(
|
|
663
|
-
|
|
662
|
+
(v = j.callbacks) === null || v === void 0 || v.forEach((C) => {
|
|
663
|
+
C(f, g);
|
|
664
664
|
});
|
|
665
665
|
});
|
|
666
666
|
} else {
|
|
667
|
-
const
|
|
668
|
-
|
|
669
|
-
|
|
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
|
|
672
|
+
return o;
|
|
673
673
|
}
|
|
674
|
-
|
|
674
|
+
ke.createDraft = rt;
|
|
675
675
|
Object.prototype.constructor.toString();
|
|
676
|
-
const
|
|
676
|
+
const z = [];
|
|
677
677
|
for (let e = 0; e < 256; ++e)
|
|
678
|
-
|
|
679
|
-
function
|
|
680
|
-
return (
|
|
681
|
-
}
|
|
682
|
-
let
|
|
683
|
-
const
|
|
684
|
-
function
|
|
685
|
-
if (!
|
|
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
|
-
|
|
688
|
+
Ie = crypto.getRandomValues.bind(crypto);
|
|
689
689
|
}
|
|
690
|
-
return
|
|
690
|
+
return Ie(Nt);
|
|
691
691
|
}
|
|
692
|
-
const
|
|
693
|
-
function
|
|
694
|
-
if (
|
|
695
|
-
return
|
|
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
|
|
698
|
-
if (
|
|
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
|
|
700
|
+
return i[6] = i[6] & 15 | 64, i[8] = i[8] & 63 | 128, Ot(i);
|
|
701
701
|
}
|
|
702
|
-
function
|
|
703
|
-
return
|
|
702
|
+
function St() {
|
|
703
|
+
return At();
|
|
704
704
|
}
|
|
705
|
-
function
|
|
705
|
+
function It(e, t) {
|
|
706
706
|
return e.localeCompare(t);
|
|
707
707
|
}
|
|
708
|
-
function
|
|
709
|
-
let e =
|
|
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
|
-
|
|
718
|
-
function
|
|
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
|
|
733
|
-
function
|
|
734
|
-
const
|
|
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(
|
|
739
|
-
get: (
|
|
740
|
-
if (
|
|
738
|
+
return new Proxy(i, {
|
|
739
|
+
get: (r, s) => {
|
|
740
|
+
if (s === "__ops")
|
|
741
741
|
return n;
|
|
742
|
-
if (
|
|
742
|
+
if (s === "__etype")
|
|
743
743
|
return e;
|
|
744
|
-
if (
|
|
745
|
-
return (
|
|
744
|
+
if (jt.has(s))
|
|
745
|
+
return (a, u) => xe(e, t, [
|
|
746
746
|
...n,
|
|
747
|
-
|
|
747
|
+
u ? [s, e, t, a, u] : [s, e, t, a]
|
|
748
748
|
]);
|
|
749
749
|
}
|
|
750
750
|
});
|
|
751
751
|
}
|
|
752
|
-
function
|
|
752
|
+
function xt(e) {
|
|
753
753
|
return e.startsWith("lookup__");
|
|
754
754
|
}
|
|
755
|
-
function
|
|
756
|
-
const [t, n, ...
|
|
757
|
-
return [n, JSON.parse(
|
|
755
|
+
function Rt(e) {
|
|
756
|
+
const [t, n, ...i] = e.split("__");
|
|
757
|
+
return [n, JSON.parse(i.join("__"))];
|
|
758
758
|
}
|
|
759
|
-
function
|
|
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
|
|
767
|
-
return
|
|
766
|
+
const i = n;
|
|
767
|
+
return xt(i) ? xe(e, Rt(i), []) : xe(e, i, []);
|
|
768
768
|
}
|
|
769
769
|
});
|
|
770
770
|
}
|
|
771
|
-
function
|
|
771
|
+
function Et() {
|
|
772
772
|
return new Proxy({}, {
|
|
773
773
|
get(e, t) {
|
|
774
|
-
return
|
|
774
|
+
return Dt(t);
|
|
775
775
|
}
|
|
776
776
|
});
|
|
777
777
|
}
|
|
778
|
-
|
|
779
|
-
const
|
|
780
|
-
Object.assign(Object.assign({},
|
|
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
|
|
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
|
|
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
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
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
|
|
824
|
+
return le()[t] ?? Ne[t];
|
|
797
825
|
},
|
|
798
826
|
has(e, t) {
|
|
799
|
-
|
|
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
|
|
804
|
-
return
|
|
830
|
+
const i = le(!0);
|
|
831
|
+
return i[t] = n, !0;
|
|
805
832
|
},
|
|
806
833
|
deleteProperty(e, t) {
|
|
807
|
-
if (!t)
|
|
808
|
-
|
|
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 =
|
|
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
|
|
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
|
|
822
|
-
eterm:
|
|
823
|
-
cons25:
|
|
824
|
-
console:
|
|
825
|
-
cygwin:
|
|
826
|
-
dtterm:
|
|
827
|
-
gnome:
|
|
828
|
-
hurd:
|
|
829
|
-
jfbterm:
|
|
830
|
-
konsole:
|
|
831
|
-
kterm:
|
|
832
|
-
mlterm:
|
|
833
|
-
mosh:
|
|
834
|
-
putty:
|
|
835
|
-
st:
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
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
|
|
865
|
-
if (
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
if (
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
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
|
|
895
|
-
|
|
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 !
|
|
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
|
|
912
|
+
return Y;
|
|
904
913
|
case "Apple_Terminal":
|
|
905
|
-
return
|
|
914
|
+
return ee;
|
|
906
915
|
}
|
|
907
|
-
if (
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
if (
|
|
911
|
-
|
|
912
|
-
if (
|
|
913
|
-
|
|
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
|
|
924
|
+
return L("COLORTERM") ? B : pe;
|
|
921
925
|
}
|
|
922
|
-
const
|
|
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
|
-
},
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
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
|
|
972
|
+
return n;
|
|
968
973
|
}
|
|
969
974
|
};
|
|
970
|
-
},
|
|
971
|
-
function
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
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
|
-
|
|
987
|
-
const t =
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
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
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
fieldName: e.rateLimit?.fields?.lastRequest || "lastRequest"
|
|
1049
|
+
output: (v) => {
|
|
1050
|
+
if (v)
|
|
1051
|
+
return String(v);
|
|
1018
1052
|
}
|
|
1019
1053
|
}
|
|
1020
|
-
}
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
|
|
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
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
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
|
-
|
|
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
|
-
...
|
|
1273
|
+
...r?.fields,
|
|
1117
1274
|
...e.user?.additionalFields
|
|
1118
1275
|
},
|
|
1119
1276
|
order: 1
|
|
1120
1277
|
},
|
|
1121
|
-
|
|
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
|
-
...
|
|
1356
|
+
...a?.fields,
|
|
1194
1357
|
...e.account?.additionalFields
|
|
1195
1358
|
},
|
|
1196
1359
|
order: 3
|
|
1197
1360
|
},
|
|
1198
|
-
verification: {
|
|
1199
|
-
|
|
1200
|
-
|
|
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
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
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
|
|
1329
|
-
return e;
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
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
|
|
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
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
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
|
-
|
|
1654
|
-
|
|
1392
|
+
const He = "db.collection.name", We = "db.operation.name";
|
|
1393
|
+
function Q(e, t, n) {
|
|
1394
|
+
return n();
|
|
1655
1395
|
}
|
|
1656
|
-
|
|
1657
|
-
|
|
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
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
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
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
if (
|
|
1756
|
-
|
|
1757
|
-
if (
|
|
1758
|
-
|
|
1759
|
-
if (
|
|
1760
|
-
|
|
1761
|
-
if (
|
|
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
|
-
|
|
1773
|
-
} else
|
|
1774
|
-
Y.info(`[${i.adapterName}]`, ...u);
|
|
1436
|
+
b.info(`[${r.adapterName}]`, ...l);
|
|
1437
|
+
} else b.info(`[${r.adapterName}]`, ...l);
|
|
1775
1438
|
}
|
|
1776
|
-
},
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
})
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
}) => {
|
|
1802
|
-
const p = s
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
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
|
-
})),
|
|
1491
|
+
})), O !== void 0 && (p[I] = O);
|
|
1828
1492
|
}
|
|
1829
|
-
return
|
|
1830
|
-
},
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
([
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
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
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
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
|
|
1861
|
-
},
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
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
|
-
|
|
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:
|
|
1906
|
-
debugLog:
|
|
1907
|
-
getFieldName:
|
|
1908
|
-
getModelName:
|
|
1909
|
-
getDefaultModelName:
|
|
1910
|
-
getDefaultFieldName:
|
|
1911
|
-
getFieldAttributes:
|
|
1912
|
-
transformInput:
|
|
1913
|
-
transformOutput:
|
|
1914
|
-
transformWhereClause:
|
|
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
|
|
1917
|
-
const
|
|
1918
|
-
transaction: async (
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
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(
|
|
1705
|
+
console.log(S), l.id = void 0;
|
|
1940
1706
|
}
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
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
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
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
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
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
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
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
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
model:
|
|
2068
|
-
|
|
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
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
)
|
|
2076
|
-
|
|
2077
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
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
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
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
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
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
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
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
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
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
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
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
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
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
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
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
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
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
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
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
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
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
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
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:
|
|
2223
|
-
const
|
|
2224
|
-
return n.secondaryStorage && !n.session?.storeSessionInDatabase && delete
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
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:
|
|
2255
|
-
...
|
|
1934
|
+
adapterConfig: r,
|
|
1935
|
+
...C.options ?? {}
|
|
2256
1936
|
},
|
|
2257
|
-
id:
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
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
|
|
1953
|
+
return Ve;
|
|
2287
1954
|
};
|
|
2288
|
-
function
|
|
2289
|
-
return
|
|
1955
|
+
function D(e) {
|
|
1956
|
+
return it() < 8 ? `#${e}` : `${U.fg.magenta}#${e}${U.reset}`;
|
|
2290
1957
|
}
|
|
2291
|
-
function
|
|
2292
|
-
return `${
|
|
1958
|
+
function E(e, t) {
|
|
1959
|
+
return `${U.bg.black}${U.fg.yellow}[${e}/${t}]${U.reset}`;
|
|
2293
1960
|
}
|
|
2294
|
-
function
|
|
2295
|
-
return `${
|
|
1961
|
+
function k(e) {
|
|
1962
|
+
return `${U.bright}${e}${U.reset}`;
|
|
2296
1963
|
}
|
|
2297
|
-
function
|
|
2298
|
-
return `${
|
|
1964
|
+
function q(e) {
|
|
1965
|
+
return `${U.dim}(${e})${U.reset}`;
|
|
2299
1966
|
}
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
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
|
|
1976
|
+
function ct(e, t) {
|
|
2305
1977
|
return e.toLowerCase().endsWith("id") ? e.slice(0, -2) : t;
|
|
2306
1978
|
}
|
|
2307
|
-
function
|
|
2308
|
-
const { type:
|
|
2309
|
-
let
|
|
2310
|
-
switch (
|
|
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
|
-
|
|
1984
|
+
o = "i.string()";
|
|
2313
1985
|
break;
|
|
2314
1986
|
case "boolean":
|
|
2315
|
-
|
|
1987
|
+
o = "i.boolean()";
|
|
2316
1988
|
break;
|
|
2317
1989
|
case "date":
|
|
2318
|
-
|
|
1990
|
+
o = "i.date()";
|
|
2319
1991
|
break;
|
|
2320
1992
|
case "number":
|
|
2321
|
-
|
|
1993
|
+
o = "i.number()";
|
|
2322
1994
|
break;
|
|
2323
1995
|
case "json":
|
|
2324
|
-
|
|
1996
|
+
o = "i.json()";
|
|
2325
1997
|
break;
|
|
2326
1998
|
case "number[]":
|
|
2327
|
-
|
|
1999
|
+
o = "i.json()";
|
|
2328
2000
|
break;
|
|
2329
2001
|
case "string[]":
|
|
2330
|
-
|
|
2002
|
+
o = "i.json()";
|
|
2331
2003
|
break;
|
|
2332
2004
|
default:
|
|
2333
|
-
|
|
2005
|
+
o = "i.string()";
|
|
2334
2006
|
}
|
|
2335
|
-
return
|
|
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
|
|
2009
|
+
function Ye(e, t, n) {
|
|
2338
2010
|
return e === "user" ? "$users" : n ? `${t}s` : t;
|
|
2339
2011
|
}
|
|
2340
|
-
function
|
|
2012
|
+
function Qt(e) {
|
|
2341
2013
|
return e.charAt(0).toLowerCase() + e.slice(1);
|
|
2342
2014
|
}
|
|
2343
|
-
function
|
|
2344
|
-
const n = {},
|
|
2345
|
-
for (const [
|
|
2346
|
-
const { modelName:
|
|
2347
|
-
|
|
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 [
|
|
2350
|
-
const { modelName:
|
|
2351
|
-
for (const [c,
|
|
2352
|
-
const { references:
|
|
2353
|
-
if (
|
|
2354
|
-
const { model:
|
|
2355
|
-
if (!
|
|
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 "${
|
|
2029
|
+
`Warning: Could not find entity name for model "${g}" referenced by ${a}.${c}`
|
|
2358
2030
|
);
|
|
2359
2031
|
continue;
|
|
2360
2032
|
}
|
|
2361
|
-
const
|
|
2362
|
-
n[
|
|
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:
|
|
2036
|
+
on: o,
|
|
2365
2037
|
has: "one",
|
|
2366
|
-
label:
|
|
2367
|
-
onDelete:
|
|
2038
|
+
label: j,
|
|
2039
|
+
onDelete: $ || "cascade"
|
|
2368
2040
|
},
|
|
2369
2041
|
reverse: {
|
|
2370
|
-
on:
|
|
2042
|
+
on: v,
|
|
2371
2043
|
has: "many",
|
|
2372
|
-
label:
|
|
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
|
|
2052
|
+
function tn(e, t) {
|
|
2381
2053
|
const n = {};
|
|
2382
|
-
for (const [
|
|
2383
|
-
const { modelName: c, fields:
|
|
2384
|
-
for (const [
|
|
2385
|
-
const
|
|
2386
|
-
|
|
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
|
|
2389
|
-
n[
|
|
2390
|
-
${
|
|
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
|
|
2395
|
-
`),
|
|
2396
|
-
const c =
|
|
2397
|
-
return ` ${
|
|
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: "${
|
|
2406
|
-
has: "${
|
|
2407
|
-
label: "${
|
|
2077
|
+
on: "${d.on}",
|
|
2078
|
+
has: "${d.has}",
|
|
2079
|
+
label: "${d.label}"
|
|
2408
2080
|
}
|
|
2409
2081
|
}`;
|
|
2410
2082
|
}).join(`,
|
|
2411
|
-
`),
|
|
2083
|
+
`), a = s ? `,
|
|
2412
2084
|
links: {
|
|
2413
|
-
${
|
|
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
|
-
${
|
|
2422
|
-
}${
|
|
2093
|
+
${r}
|
|
2094
|
+
}${a}
|
|
2423
2095
|
})
|
|
2424
2096
|
`;
|
|
2425
2097
|
}
|
|
2426
|
-
function
|
|
2098
|
+
function nn(e, t, n) {
|
|
2427
2099
|
return e === "user" ? "$users" : n ? `${t}s` : t;
|
|
2428
2100
|
}
|
|
2429
|
-
function
|
|
2101
|
+
function rn(e, t) {
|
|
2430
2102
|
const n = {};
|
|
2431
|
-
for (const [
|
|
2432
|
-
const { modelName:
|
|
2433
|
-
n[
|
|
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
|
|
2109
|
+
function on({
|
|
2438
2110
|
db: e,
|
|
2439
2111
|
model: t,
|
|
2440
2112
|
modelSchema: n,
|
|
2441
|
-
data:
|
|
2442
|
-
entityNameMap:
|
|
2113
|
+
data: i,
|
|
2114
|
+
entityNameMap: r
|
|
2443
2115
|
}) {
|
|
2444
|
-
const
|
|
2445
|
-
for (const [
|
|
2446
|
-
const { references:
|
|
2447
|
-
if (
|
|
2448
|
-
const { model:
|
|
2449
|
-
if (!
|
|
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 "${
|
|
2123
|
+
`Warning: Could not find entity name for model "${f}" referenced by ${u}.${o}`
|
|
2452
2124
|
);
|
|
2453
2125
|
continue;
|
|
2454
2126
|
}
|
|
2455
|
-
const
|
|
2456
|
-
if (
|
|
2457
|
-
const
|
|
2458
|
-
[
|
|
2459
|
-
},
|
|
2460
|
-
|
|
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
|
|
2136
|
+
return s;
|
|
2465
2137
|
}
|
|
2466
|
-
const
|
|
2138
|
+
const cn = ({
|
|
2467
2139
|
db: e,
|
|
2468
2140
|
usePlural: t = !0,
|
|
2469
2141
|
debugLogs: n = !1
|
|
2470
|
-
}) =>
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
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
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
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:
|
|
2603
|
-
limit:
|
|
2604
|
-
offset:
|
|
2605
|
-
sortBy:
|
|
2296
|
+
where: i,
|
|
2297
|
+
limit: r,
|
|
2298
|
+
offset: s,
|
|
2299
|
+
sortBy: a
|
|
2606
2300
|
}) {
|
|
2607
|
-
let
|
|
2608
|
-
|
|
2609
|
-
[
|
|
2301
|
+
let u;
|
|
2302
|
+
a && (u = {
|
|
2303
|
+
[a.field]: a.direction
|
|
2610
2304
|
});
|
|
2611
|
-
const
|
|
2612
|
-
[n]: { $: { where:
|
|
2305
|
+
const o = {
|
|
2306
|
+
[n]: { $: { where: sn(i), limit: r, offset: s, order: u } }
|
|
2613
2307
|
};
|
|
2614
|
-
t("Query",
|
|
2615
|
-
const c = await e.query(
|
|
2616
|
-
return t("Result",
|
|
2308
|
+
t("Query", he(o));
|
|
2309
|
+
const c = await e.query(o);
|
|
2310
|
+
return t("Result", he(c)), c[n];
|
|
2617
2311
|
}
|
|
2618
|
-
function
|
|
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
|
|
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
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2354
|
+
cn as instantAdapter,
|
|
2355
|
+
un as instantAuth,
|
|
2356
|
+
sn as parseWhere
|
|
2663
2357
|
};
|