@stoker-platform/node-client 0.5.12 → 0.5.13

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/bundle.js CHANGED
@@ -15,7 +15,7 @@ const jn = (n) => !!n.auth, Te = (n, e) => {
15
15
  const { labels: s } = n;
16
16
  return t.collections && // eslint-disable-next-line security/detect-object-injection
17
17
  Te("Update", t.collections[s.collection]) && (!e.access || Zn(e, t)) && ai(e, t) && !(n.auth && !t.collections?.[s.collection].auth && ["Enabled", "Role", "Name", "Email", "Photo_URL"].includes(e.name));
18
- }, W = (n, e) => n.filter((t) => t.name === e)[0], K = (n) => ["OneToOne", "OneToMany", "ManyToOne", "ManyToMany"].includes(n.type), li = (n, e) => {
18
+ }, V = (n, e) => n.filter((t) => t.name === e)[0], K = (n) => ["OneToOne", "OneToMany", "ManyToOne", "ManyToMany"].includes(n.type), li = (n, e) => {
19
19
  const t = {
20
20
  Record_Owner: "recordOwner",
21
21
  Record_User: "recordUser",
@@ -39,7 +39,7 @@ const jn = (n) => !!n.auth, Te = (n, e) => {
39
39
  return i?.parentFilters?.forEach((o) => {
40
40
  if (!o.roles.some((d) => d.role === t.Role))
41
41
  return;
42
- const a = o.collectionField, l = W(n.fields, a);
42
+ const a = o.collectionField, l = V(n.fields, a);
43
43
  if (!K(l))
44
44
  throw new Error("PERMISSION_DENIED");
45
45
  const c = t.collections?.[l.collection], h = e.collections[l.collection].access.entityRestrictions;
@@ -75,31 +75,31 @@ const jn = (n) => !!n.auth, Te = (n, e) => {
75
75
  }), c?.filter((p) => p.type === "Record_User").forEach((p) => {
76
76
  if ("operations" in p && p.operations && !p.operations.includes(n))
77
77
  return;
78
- const T = W(o, p.collectionField);
79
- i[`${T.name}_Array`]?.includes(r.Doc_ID) || (l = !1);
78
+ const R = V(o, p.collectionField);
79
+ i[`${R.name}_Array`]?.includes(r.Doc_ID) || (l = !1);
80
80
  }), c?.filter((p) => p.type === "Record_Property").forEach((p) => {
81
81
  if ("operations" in p && p.operations && !p.operations.includes(n))
82
82
  return;
83
- const T = W(o, p.propertyField), C = p.roles.find((v) => v.role === r.Role);
84
- T.type === "Array" ? C.values?.some((v) => i[T.name].includes(v)) || (l = !1) : C.values?.includes(i[T.name]) || (l = !1);
83
+ const R = V(o, p.propertyField), A = p.roles.find((v) => v.role === r.Role);
84
+ R.type === "Array" ? A.values?.some((v) => i[R.name].includes(v)) || (l = !1) : A.values?.includes(i[R.name]) || (l = !1);
85
85
  });
86
86
  let f = !0, d = !1;
87
87
  u?.filter((p) => p.type === "Individual").forEach(() => {
88
88
  d = !0, a.individualEntities?.includes(i.id) || (f = !1);
89
89
  });
90
- let m = !0, k = !1;
90
+ let m = !0, b = !1;
91
91
  if (u?.filter((p) => p.type === "Parent").forEach((p) => {
92
- k = !0;
93
- const T = W(o, p.collectionField);
94
- a.parentEntities?.some((C) => i[`${T.name}_Array`].includes(C)) || (m = !1);
92
+ b = !0;
93
+ const R = V(o, p.collectionField);
94
+ a.parentEntities?.some((A) => i[`${R.name}_Array`].includes(A)) || (m = !1);
95
95
  }), u?.filter((p) => p.type === "Parent_Property").forEach((p) => {
96
- k = !0;
97
- const T = W(o, p.collectionField), C = W(o, p.propertyField);
96
+ b = !0;
97
+ const R = V(o, p.collectionField), A = V(o, p.propertyField);
98
98
  Object.entries(a.parentPropertyEntities || {}).some((v) => {
99
- const [Z, x] = v;
100
- return Z === i[C.name] && i[`${T.name}_Array`].some((g) => x.includes(g));
99
+ const [j, I] = v;
100
+ return j === i[A.name] && i[`${R.name}_Array`].some((g) => I.includes(g));
101
101
  }) || (m = !1);
102
- }), d && k) {
102
+ }), d && b) {
103
103
  if (!(f || m)) {
104
104
  l = !1;
105
105
  return;
@@ -108,42 +108,42 @@ const jn = (n) => !!n.auth, Te = (n, e) => {
108
108
  l = !1;
109
109
  return;
110
110
  }
111
- let y = !0, w = !1;
111
+ let y = !0, _ = !1;
112
112
  h?.filter((p) => p.parentFilter.type === "Individual").forEach((p) => {
113
- w = !0;
114
- const { parentFilter: T } = p, C = W(o, T.collectionField), v = r.collections?.[C.collection];
113
+ _ = !0;
114
+ const { parentFilter: R } = p, A = V(o, R.collectionField), v = r.collections?.[A.collection];
115
115
  if (!v) {
116
116
  l = !1;
117
117
  return;
118
118
  }
119
- v.individualEntities?.some((Z) => i[`${C.name}_Array`].includes(Z)) || (y = !1);
119
+ v.individualEntities?.some((j) => i[`${A.name}_Array`].includes(j)) || (y = !1);
120
120
  });
121
- let b = !0, N = !1;
121
+ let S = !0, x = !1;
122
122
  if (h?.filter((p) => p.parentFilter.type === "Parent").forEach((p) => {
123
- N = !0;
124
- const { parentFilter: T } = p, C = W(o, T.collectionField), v = W(o, T.parentCollectionField), Z = r.collections?.[C.collection];
125
- if (!Z) {
123
+ x = !0;
124
+ const { parentFilter: R } = p, A = V(o, R.collectionField), v = V(o, R.parentCollectionField), j = r.collections?.[A.collection];
125
+ if (!j) {
126
126
  l = !1;
127
127
  return;
128
128
  }
129
- Z.parentEntities?.some((x) => i[`${v.name}_Array`].includes(x)) || (b = !1);
129
+ j.parentEntities?.some((I) => i[`${v.name}_Array`].includes(I)) || (S = !1);
130
130
  }), h?.filter((p) => p.parentFilter.type === "Parent_Property").forEach((p) => {
131
- N = !0;
132
- const { parentFilter: T } = p, C = W(o, T.collectionField), v = W(o, T.parentPropertyField), Z = W(o, T.parentCollectionField), x = r.collections?.[C.collection];
133
- if (!x) {
131
+ x = !0;
132
+ const { parentFilter: R } = p, A = V(o, R.collectionField), v = V(o, R.parentPropertyField), j = V(o, R.parentCollectionField), I = r.collections?.[A.collection];
133
+ if (!I) {
134
134
  l = !1;
135
135
  return;
136
136
  }
137
- Object.entries(x.parentPropertyEntities || {}).some((g) => {
138
- const [O, _] = g;
139
- return O === i[v.name] && i[`${Z.name}_Array`].some((A) => _.includes(A));
140
- }) || (b = !1);
141
- }), w && N) {
142
- if (!(y || b)) {
137
+ Object.entries(I.parentPropertyEntities || {}).some((g) => {
138
+ const [k, E] = g;
139
+ return k === i[v.name] && i[`${j.name}_Array`].some((B) => E.includes(B));
140
+ }) || (S = !1);
141
+ }), _ && x) {
142
+ if (!(y || S)) {
143
143
  l = !1;
144
144
  return;
145
145
  }
146
- } else if (!y || !b) {
146
+ } else if (!y || !S) {
147
147
  l = !1;
148
148
  return;
149
149
  }
@@ -259,30 +259,30 @@ const jn = (n) => !!n.auth, Te = (n, e) => {
259
259
  for (const i of Object.values(n.collections)) {
260
260
  const { labels: o, access: a, fields: l } = i, { operations: c, attributeRestrictions: u, entityRestrictions: h } = a, f = c.assignable, d = e.collections?.[o.collection], m = ["read", "create", "update", "delete"];
261
261
  if (f !== !0 && !(typeof f == "object" && f.includes(t)) ? m.forEach((y) => {
262
- const w = y.charAt(0).toUpperCase() + y.slice(1);
262
+ const _ = y.charAt(0).toUpperCase() + y.slice(1);
263
263
  if (y !== "assignable") {
264
- const b = !!a.operations[y]?.includes(t), N = !!d?.operations.includes(w);
265
- if (!b && N) {
264
+ const S = !!a.operations[y]?.includes(t), x = !!d?.operations.includes(_);
265
+ if (!S && x) {
266
266
  r = `Collection ${o.collection} has excess ${y} operation for role ${t}`, s = !1;
267
267
  return;
268
268
  }
269
- if (b && !N) {
269
+ if (S && !x) {
270
270
  r = `Collection ${o.collection} has missing ${y} operation for role ${t}`, s = !1;
271
271
  return;
272
272
  }
273
273
  }
274
274
  }) : m.forEach((y) => {
275
- const w = y.charAt(0).toUpperCase() + y.slice(1);
275
+ const _ = y.charAt(0).toUpperCase() + y.slice(1);
276
276
  if (y !== "assignable") {
277
- const b = !!a.operations[y]?.includes(t), N = !!d?.operations.includes(w);
278
- if (!b && N) {
277
+ const S = !!a.operations[y]?.includes(t), x = !!d?.operations.includes(_);
278
+ if (!S && x) {
279
279
  r = `Collection ${o.collection} has excess ${y} operation for role ${t}`, s = !1;
280
280
  return;
281
281
  }
282
282
  }
283
283
  }), !u && !h || (u?.forEach((y) => {
284
- for (const w of y.roles)
285
- if (w.role === t && !w.assignable) {
284
+ for (const _ of y.roles)
285
+ if (_.role === t && !_.assignable) {
286
286
  if (y.type === "Record_Owner" && !e.collections?.[o.collection]?.recordOwner?.active) {
287
287
  r = `Collection ${o.collection} is missing Record_Owner restriction for role ${t}`, s = !1;
288
288
  return;
@@ -298,17 +298,17 @@ const jn = (n) => !!n.auth, Te = (n, e) => {
298
298
  }
299
299
  }), h?.assignable?.includes(t)))
300
300
  continue;
301
- let k = !1;
301
+ let b = !1;
302
302
  if (h?.restrictions?.forEach((y) => {
303
- for (const w of y.roles)
304
- if (w.role === t) {
305
- if (k = !0, y.type === "Individual" && !e.collections?.[o.collection]?.individualEntities) {
303
+ for (const _ of y.roles)
304
+ if (_.role === t) {
305
+ if (b = !0, y.type === "Individual" && !e.collections?.[o.collection]?.individualEntities) {
306
306
  r = `Collection ${o.collection} is missing individual entities`, s = !1;
307
307
  return;
308
308
  }
309
309
  if (y.type === "Parent") {
310
- const b = W(l, y.collectionField);
311
- if (!K(b)) {
310
+ const S = V(l, y.collectionField);
311
+ if (!K(S)) {
312
312
  s = !1;
313
313
  return;
314
314
  }
@@ -318,18 +318,18 @@ const jn = (n) => !!n.auth, Te = (n, e) => {
318
318
  }
319
319
  }
320
320
  if (y.type === "Parent_Property") {
321
- const b = W(l, y.collectionField);
322
- if (!K(b)) {
321
+ const S = V(l, y.collectionField);
322
+ if (!K(S)) {
323
323
  s = !1;
324
324
  return;
325
325
  }
326
- if (!e.collections?.[o.collection]?.parentPropertyEntities?.[b.collection]) {
326
+ if (!e.collections?.[o.collection]?.parentPropertyEntities?.[S.collection]) {
327
327
  r = `Collection ${o.collection} is missing parent property entities`, s = !1;
328
328
  return;
329
329
  }
330
330
  }
331
331
  }
332
- }), k && !e.collections?.[o.collection]?.restrictEntities) {
332
+ }), b && !e.collections?.[o.collection]?.restrictEntities) {
333
333
  r = `Collection ${o.collection} must have restrictEntities set to true`, s = !1;
334
334
  return;
335
335
  }
@@ -341,19 +341,19 @@ const jn = (n) => !!n.auth, Te = (n, e) => {
341
341
  const d = u?.filter((m) => s === m.userRole);
342
342
  return d?.length && !d.some((m) => m.recordRole === r) ? (f = `User ${s} does not have write access to record with role ${r}`, h = !1, h) : n === "update" && // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
343
343
  o.User_ID && d?.length && !d.some((m) => m.recordRole === a) ? (f = `User ${s} does not have write access to record with role ${r}`, h = !1, h) : (u?.forEach((m) => {
344
- s === m.userRole && m.recordRole === r && n !== "delete" && i && Object.keys(t.collections).forEach((k) => {
345
- const y = i.collections?.[k], w = l?.collections?.[k];
346
- if (!(n === "update" && ze(y, w)) && y) {
347
- const b = m.collections.some((N) => N.collection === k);
348
- if (b) {
349
- if (b) {
350
- const N = m.collections.find((T) => T.collection === k);
351
- if (!(y.operations.every((T) => N.operations.includes(T)) || n === "update" && ze(y.operations, w?.operations))) {
352
- f = `User ${s} does not have write access to all included operations for collection ${k}`, h = !1;
344
+ s === m.userRole && m.recordRole === r && n !== "delete" && i && Object.keys(t.collections).forEach((b) => {
345
+ const y = i.collections?.[b], _ = l?.collections?.[b];
346
+ if (!(n === "update" && ze(y, _)) && y) {
347
+ const S = m.collections.some((x) => x.collection === b);
348
+ if (S) {
349
+ if (S) {
350
+ const x = m.collections.find((R) => R.collection === b);
351
+ if (!(y.operations.every((R) => x.operations.includes(R)) || n === "update" && ze(y.operations, _?.operations))) {
352
+ f = `User ${s} does not have write access to all included operations for collection ${b}`, h = !1;
353
353
  return;
354
354
  }
355
- if (!N.auth && y.auth && !(n === "update" && ze(y.auth, w?.auth))) {
356
- f = `User ${s} does not have write access to auth for collection ${k}`, h = !1;
355
+ if (!x.auth && y.auth && !(n === "update" && ze(y.auth, _?.auth))) {
356
+ f = `User ${s} does not have write access to auth for collection ${b}`, h = !1;
357
357
  return;
358
358
  }
359
359
  const p = {
@@ -361,19 +361,19 @@ const jn = (n) => !!n.auth, Te = (n, e) => {
361
361
  recordUser: "Record_User",
362
362
  recordProperty: "Record_Property"
363
363
  };
364
- if (Object.keys(p).forEach((T) => {
365
- const C = p[T];
366
- if (N.attributeRestrictions?.includes(C) && !(y[T]?.active || n === "update" && ze(y[T], w?.[T]))) {
367
- f = `User ${s} does not have write access to attribute restriction ${T} for collection ${k}`, h = !1;
364
+ if (Object.keys(p).forEach((R) => {
365
+ const A = p[R];
366
+ if (x.attributeRestrictions?.includes(A) && !(y[R]?.active || n === "update" && ze(y[R], _?.[R]))) {
367
+ f = `User ${s} does not have write access to attribute restriction ${R} for collection ${b}`, h = !1;
368
368
  return;
369
369
  }
370
- }), N.restrictEntities && !y.restrictEntities && !(n === "update" && ze(y.restrictEntities, w?.restrictEntities))) {
371
- f = `User ${s} does not have write access to restrictEntities for collection ${k}`, h = !1;
370
+ }), x.restrictEntities && !y.restrictEntities && !(n === "update" && ze(y.restrictEntities, _?.restrictEntities))) {
371
+ f = `User ${s} does not have write access to restrictEntities for collection ${b}`, h = !1;
372
372
  return;
373
373
  }
374
374
  }
375
375
  } else {
376
- f = `User ${s} does not have write access to collection ${k}`, h = !1;
376
+ f = `User ${s} does not have write access to collection ${b}`, h = !1;
377
377
  return;
378
378
  }
379
379
  }
@@ -450,18 +450,18 @@ const jn = (n) => !!n.auth, Te = (n, e) => {
450
450
  }, or = (n, e, t, s, r, i, o, a, l, c) => {
451
451
  const { labels: u, fields: h } = s, f = o?.collections?.[u.collection], d = { ...e, ...n };
452
452
  nt(d);
453
- let m = !0, k = "";
453
+ let m = !0, b = "";
454
454
  if (i && !f)
455
455
  throw new Error("PERMISSION_DENIED");
456
- i && !Te("Update", f) && (m = !1, k = "Authenticated user does not have Update access to this collection"), i && // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
456
+ i && !Te("Update", f) && (m = !1, b = "Authenticated user does not have Update access to this collection"), i && // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
457
457
  (!it("Update", s, r, i, o, e) || // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
458
- !it("Update", s, r, i, o, d)) && (m = !1, k = "Authenticated user does not have Update access to this document"), a && (i && !jn(f) && (m = !1, k = "Authenticated user does not have Auth access for this collection"), Vs("update", d, t, s, r, i, o, l, c, e, a) || (k = "Authenticated user does not have sufficient write access for this record", m = !1));
458
+ !it("Update", s, r, i, o, d)) && (m = !1, b = "Authenticated user does not have Update access to this document"), a && (i && !jn(f) && (m = !1, b = "Authenticated user does not have Auth access for this collection"), Vs("update", d, t, s, r, i, o, l, c, e, a) || (b = "Authenticated user does not have sufficient write access for this record", m = !1));
459
459
  for (const y of h) {
460
- const w = n[y.name];
461
- y.access && !Zn(y, o) && w !== void 0 && (k = `Authenticated user does not have access to field ${y.name}`, m = !1), w !== void 0 && !ai(y, o) && (k = `Authenticated user does not have Update access to field ${y.name}`, m = !1);
460
+ const _ = n[y.name];
461
+ y.access && !Zn(y, o) && _ !== void 0 && (b = `Authenticated user does not have access to field ${y.name}`, m = !1), _ !== void 0 && !ai(y, o) && (b = `Authenticated user does not have Update access to field ${y.name}`, m = !1);
462
462
  }
463
463
  if (!m)
464
- throw k && console.error(`PERMISSION_DENIED: ${k}`), new Error("PERMISSION_DENIED");
464
+ throw b && console.error(`PERMISSION_DENIED: ${b}`), new Error("PERMISSION_DENIED");
465
465
  }, Qo = (n, e, t, s, r, i) => {
466
466
  const { labels: o } = t, a = i.collections?.[o.collection];
467
467
  let l = !0;
@@ -504,7 +504,7 @@ const jn = (n) => !!n.auth, Te = (n, e) => {
504
504
  for (const i of r.parentFilters) {
505
505
  if (!i.roles.some((c) => c.role === n))
506
506
  continue;
507
- const o = W(e.fields, i.collectionField);
507
+ const o = V(e.fields, i.collectionField);
508
508
  if (!K(o))
509
509
  throw new Error("PERMISSION_DENIED");
510
510
  const l = t.collections[o.collection].access.entityRestrictions?.restrictions?.find((c) => c.type === i.type && c.roles.some((u) => u.role === n));
@@ -656,39 +656,39 @@ const jn = (n) => !!n.auth, Te = (n, e) => {
656
656
  if (l.roles.some((c) => c.role === e))
657
657
  switch (l.type) {
658
658
  case "Record_Owner":
659
- t.push(W(a, "Created_By"));
659
+ t.push(V(a, "Created_By"));
660
660
  break;
661
661
  case "Record_User":
662
- t.push(W(r, l.collectionField));
662
+ t.push(V(r, l.collectionField));
663
663
  break;
664
664
  case "Record_Property":
665
- t.push(W(r, l.propertyField));
665
+ t.push(V(r, l.propertyField));
666
666
  break;
667
667
  }
668
668
  }), o && (o.restrictions?.forEach((l) => {
669
669
  if (l.roles.some((c) => c.role === e))
670
670
  switch (l.type) {
671
671
  case "Individual":
672
- t.push(W(a, "id"));
672
+ t.push(V(a, "id"));
673
673
  break;
674
674
  case "Parent":
675
- t.push(W(r, l.collectionField));
675
+ t.push(V(r, l.collectionField));
676
676
  break;
677
677
  case "Parent_Property":
678
- t.push(W(r, l.collectionField)), t.push(W(r, l.propertyField));
678
+ t.push(V(r, l.collectionField)), t.push(V(r, l.propertyField));
679
679
  break;
680
680
  }
681
681
  }), o.parentFilters && o.parentFilters.forEach((l) => {
682
682
  if (l.roles.some((c) => c.role === e))
683
683
  switch (l.type) {
684
684
  case "Individual":
685
- t.push(W(r, l.collectionField));
685
+ t.push(V(r, l.collectionField));
686
686
  break;
687
687
  case "Parent":
688
- t.push(W(r, l.parentCollectionField));
688
+ t.push(V(r, l.parentCollectionField));
689
689
  break;
690
690
  case "Parent_Property":
691
- t.push(W(r, l.parentCollectionField)), t.push(W(r, l.parentPropertyField));
691
+ t.push(V(r, l.parentCollectionField)), t.push(V(r, l.parentPropertyField));
692
692
  break;
693
693
  }
694
694
  })), [...new Set(t)];
@@ -701,19 +701,19 @@ const jn = (n) => !!n.auth, Te = (n, e) => {
701
701
  }), s.forEach((c) => {
702
702
  (!c.access || c.access.includes(e)) && t.push(c);
703
703
  }), r?.filter((c) => (!c.roles || c.roles.includes(e)) && c.field !== "Collection_Path").forEach((c) => {
704
- t.push(W(a, c.field));
704
+ t.push(V(a, c.field));
705
705
  }), i?.range && i.range.fields.forEach((c) => {
706
- pt.includes(c) && t.push(W(a, c));
706
+ pt.includes(c) && t.push(V(a, c));
707
707
  }), o?.forEach((c) => {
708
- const u = W(s.concat(a), c.field);
709
- (!c.roles || c.roles.includes(e)) && u && (!u.access || u.access?.includes(e)) && pt.includes(c.field) && t.push(W(a, c.field));
708
+ const u = V(s.concat(a), c.field);
709
+ (!c.roles || c.roles.includes(e)) && u && (!u.access || u.access?.includes(e)) && pt.includes(c.field) && t.push(V(a, c.field));
710
710
  }), hi(n, e).forEach((c) => {
711
- pt.includes(c.name) && t.push(W(a, c.name));
711
+ pt.includes(c.name) && t.push(V(a, c.name));
712
712
  }), [...new Set(t)];
713
713
  }, ra = (n, e, t) => {
714
714
  const s = [], { fields: r, preloadCache: i } = e, o = zn();
715
715
  i?.range && i.range.fields.forEach((c) => {
716
- pt.includes(c) ? s.push(W(o, c)) : s.push(W(r, c));
716
+ pt.includes(c) ? s.push(V(o, c)) : s.push(V(r, c));
717
717
  });
718
718
  const a = /* @__PURE__ */ new Set(), l = fi(e, t);
719
719
  return Object.entries(l).map(([c, u]) => {
@@ -746,9 +746,9 @@ const jn = (n) => !!n.auth, Te = (n, e) => {
746
746
  });
747
747
  });
748
748
  }), o.forEach((l) => {
749
- s.push(W(r, l));
749
+ s.push(V(r, l));
750
750
  }), i) {
751
- const l = W(r, i.archivedField);
751
+ const l = V(r, i.archivedField);
752
752
  l && s.push(l);
753
753
  }
754
754
  return s.push(...ra(n, e, t)), [...new Set(s)];
@@ -810,7 +810,7 @@ const Ws = (n, e, t, s, r, i, o, a, l, c) => (n == "create" && (t.Collection_Pat
810
810
  const { access: t, queries: s } = n, { serverReadOnly: r } = t, i = /* @__PURE__ */ new Set();
811
811
  if (s)
812
812
  for (const o of s) {
813
- const a = W(e, o.field);
813
+ const a = V(e, o.field);
814
814
  e.find((l) => l.name === o.field) && K(a) && ["OneToOne", "OneToMany"].includes(a.type) && i.add(a);
815
815
  }
816
816
  return e.forEach((o) => {
@@ -830,7 +830,7 @@ const Ws = (n, e, t, s, r, i, o, a, l, c) => (n == "create" && (t.Collection_Pat
830
830
  e[`${i.name}_Array`] = e[i.name];
831
831
  else if (e[`${i.name}_Array`] = Object.keys(e[i.name]), i.includeFields)
832
832
  for (const o of i.includeFields) {
833
- const a = t.collections[i.collection], l = W(a.fields, o);
833
+ const a = t.collections[i.collection], l = V(a.fields, o);
834
834
  wt(a, [l]).size === 1 && Object.keys(e[i.name]).forEach((u) => {
835
835
  e[i.name][u][o] ? e[i.name][u][`${o}_Lowercase`] = e[i.name][u][o].toLowerCase() : delete e[i.name][u][`${o}_Lowercase`];
836
836
  });
@@ -856,7 +856,7 @@ const Ws = (n, e, t, s, r, i, o, a, l, c) => (n == "create" && (t.Collection_Pat
856
856
  }, oa = async (n, e, t, s) => {
857
857
  const { fields: r } = e;
858
858
  for (const i of t.fields) {
859
- const o = W(r, i.name);
859
+ const o = V(r, i.name);
860
860
  i.custom?.initialValue && !(s && o.access && !o.access.includes(s)) && (n[i.name] = await ie(i.custom.initialValue, [n]), wt(e, [o]).size === 1 && (n[`${i.name}_Lowercase`] = n[i.name].toLowerCase()));
861
861
  }
862
862
  for (const i of r)
@@ -907,7 +907,7 @@ var ar;
907
907
  // second overwrites first
908
908
  });
909
909
  })(ar || (ar = {}));
910
- const U = te.arrayToEnum([
910
+ const L = te.arrayToEnum([
911
911
  "string",
912
912
  "nan",
913
913
  "number",
@@ -931,25 +931,25 @@ const U = te.arrayToEnum([
931
931
  ]), Xe = (n) => {
932
932
  switch (typeof n) {
933
933
  case "undefined":
934
- return U.undefined;
934
+ return L.undefined;
935
935
  case "string":
936
- return U.string;
936
+ return L.string;
937
937
  case "number":
938
- return Number.isNaN(n) ? U.nan : U.number;
938
+ return Number.isNaN(n) ? L.nan : L.number;
939
939
  case "boolean":
940
- return U.boolean;
940
+ return L.boolean;
941
941
  case "function":
942
- return U.function;
942
+ return L.function;
943
943
  case "bigint":
944
- return U.bigint;
944
+ return L.bigint;
945
945
  case "symbol":
946
- return U.symbol;
946
+ return L.symbol;
947
947
  case "object":
948
- return Array.isArray(n) ? U.array : n === null ? U.null : n.then && typeof n.then == "function" && n.catch && typeof n.catch == "function" ? U.promise : typeof Map < "u" && n instanceof Map ? U.map : typeof Set < "u" && n instanceof Set ? U.set : typeof Date < "u" && n instanceof Date ? U.date : U.object;
948
+ return Array.isArray(n) ? L.array : n === null ? L.null : n.then && typeof n.then == "function" && n.catch && typeof n.catch == "function" ? L.promise : typeof Map < "u" && n instanceof Map ? L.map : typeof Set < "u" && n instanceof Set ? L.set : typeof Date < "u" && n instanceof Date ? L.date : L.object;
949
949
  default:
950
- return U.unknown;
950
+ return L.unknown;
951
951
  }
952
- }, I = te.arrayToEnum([
952
+ }, D = te.arrayToEnum([
953
953
  "invalid_type",
954
954
  "invalid_literal",
955
955
  "custom",
@@ -1034,52 +1034,52 @@ Be.create = (n) => new Be(n);
1034
1034
  const ws = (n, e) => {
1035
1035
  let t;
1036
1036
  switch (n.code) {
1037
- case I.invalid_type:
1038
- n.received === U.undefined ? t = "Required" : t = `Expected ${n.expected}, received ${n.received}`;
1037
+ case D.invalid_type:
1038
+ n.received === L.undefined ? t = "Required" : t = `Expected ${n.expected}, received ${n.received}`;
1039
1039
  break;
1040
- case I.invalid_literal:
1040
+ case D.invalid_literal:
1041
1041
  t = `Invalid literal value, expected ${JSON.stringify(n.expected, te.jsonStringifyReplacer)}`;
1042
1042
  break;
1043
- case I.unrecognized_keys:
1043
+ case D.unrecognized_keys:
1044
1044
  t = `Unrecognized key(s) in object: ${te.joinValues(n.keys, ", ")}`;
1045
1045
  break;
1046
- case I.invalid_union:
1046
+ case D.invalid_union:
1047
1047
  t = "Invalid input";
1048
1048
  break;
1049
- case I.invalid_union_discriminator:
1049
+ case D.invalid_union_discriminator:
1050
1050
  t = `Invalid discriminator value. Expected ${te.joinValues(n.options)}`;
1051
1051
  break;
1052
- case I.invalid_enum_value:
1052
+ case D.invalid_enum_value:
1053
1053
  t = `Invalid enum value. Expected ${te.joinValues(n.options)}, received '${n.received}'`;
1054
1054
  break;
1055
- case I.invalid_arguments:
1055
+ case D.invalid_arguments:
1056
1056
  t = "Invalid function arguments";
1057
1057
  break;
1058
- case I.invalid_return_type:
1058
+ case D.invalid_return_type:
1059
1059
  t = "Invalid function return type";
1060
1060
  break;
1061
- case I.invalid_date:
1061
+ case D.invalid_date:
1062
1062
  t = "Invalid date";
1063
1063
  break;
1064
- case I.invalid_string:
1064
+ case D.invalid_string:
1065
1065
  typeof n.validation == "object" ? "includes" in n.validation ? (t = `Invalid input: must include "${n.validation.includes}"`, typeof n.validation.position == "number" && (t = `${t} at one or more positions greater than or equal to ${n.validation.position}`)) : "startsWith" in n.validation ? t = `Invalid input: must start with "${n.validation.startsWith}"` : "endsWith" in n.validation ? t = `Invalid input: must end with "${n.validation.endsWith}"` : te.assertNever(n.validation) : n.validation !== "regex" ? t = `Invalid ${n.validation}` : t = "Invalid";
1066
1066
  break;
1067
- case I.too_small:
1067
+ case D.too_small:
1068
1068
  n.type === "array" ? t = `Array must contain ${n.exact ? "exactly" : n.inclusive ? "at least" : "more than"} ${n.minimum} element(s)` : n.type === "string" ? t = `String must contain ${n.exact ? "exactly" : n.inclusive ? "at least" : "over"} ${n.minimum} character(s)` : n.type === "number" ? t = `Number must be ${n.exact ? "exactly equal to " : n.inclusive ? "greater than or equal to " : "greater than "}${n.minimum}` : n.type === "bigint" ? t = `Number must be ${n.exact ? "exactly equal to " : n.inclusive ? "greater than or equal to " : "greater than "}${n.minimum}` : n.type === "date" ? t = `Date must be ${n.exact ? "exactly equal to " : n.inclusive ? "greater than or equal to " : "greater than "}${new Date(Number(n.minimum))}` : t = "Invalid input";
1069
1069
  break;
1070
- case I.too_big:
1070
+ case D.too_big:
1071
1071
  n.type === "array" ? t = `Array must contain ${n.exact ? "exactly" : n.inclusive ? "at most" : "less than"} ${n.maximum} element(s)` : n.type === "string" ? t = `String must contain ${n.exact ? "exactly" : n.inclusive ? "at most" : "under"} ${n.maximum} character(s)` : n.type === "number" ? t = `Number must be ${n.exact ? "exactly" : n.inclusive ? "less than or equal to" : "less than"} ${n.maximum}` : n.type === "bigint" ? t = `BigInt must be ${n.exact ? "exactly" : n.inclusive ? "less than or equal to" : "less than"} ${n.maximum}` : n.type === "date" ? t = `Date must be ${n.exact ? "exactly" : n.inclusive ? "smaller than or equal to" : "smaller than"} ${new Date(Number(n.maximum))}` : t = "Invalid input";
1072
1072
  break;
1073
- case I.custom:
1073
+ case D.custom:
1074
1074
  t = "Invalid input";
1075
1075
  break;
1076
- case I.invalid_intersection_types:
1076
+ case D.invalid_intersection_types:
1077
1077
  t = "Intersection results could not be merged";
1078
1078
  break;
1079
- case I.not_multiple_of:
1079
+ case D.not_multiple_of:
1080
1080
  t = `Number must be a multiple of ${n.multipleOf}`;
1081
1081
  break;
1082
- case I.not_finite:
1082
+ case D.not_finite:
1083
1083
  t = "Number must be finite";
1084
1084
  break;
1085
1085
  default:
@@ -1112,7 +1112,7 @@ const ca = (n) => {
1112
1112
  message: a
1113
1113
  };
1114
1114
  };
1115
- function L(n, e) {
1115
+ function M(n, e) {
1116
1116
  const t = la(), s = ca({
1117
1117
  issueData: e,
1118
1118
  data: n.data,
@@ -1174,10 +1174,10 @@ class ve {
1174
1174
  const Y = Object.freeze({
1175
1175
  status: "aborted"
1176
1176
  }), Bt = (n) => ({ status: "dirty", value: n }), Ae = (n) => ({ status: "valid", value: n }), lr = (n) => n.status === "aborted", cr = (n) => n.status === "dirty", xt = (n) => n.status === "valid", Nn = (n) => typeof Promise < "u" && n instanceof Promise;
1177
- var z;
1177
+ var Z;
1178
1178
  (function(n) {
1179
1179
  n.errToObj = (e) => typeof e == "string" ? { message: e } : e || {}, n.toString = (e) => typeof e == "string" ? e : e?.message;
1180
- })(z || (z = {}));
1180
+ })(Z || (Z = {}));
1181
1181
  class je {
1182
1182
  constructor(e, t, s, r) {
1183
1183
  this._cachedPath = [], this.parent = e, this.data = t, this._path = s, this._key = r;
@@ -1201,7 +1201,7 @@ const ur = (n, e) => {
1201
1201
  }
1202
1202
  };
1203
1203
  };
1204
- function J(n) {
1204
+ function Q(n) {
1205
1205
  if (!n)
1206
1206
  return {};
1207
1207
  const { errorMap: e, invalid_type_error: t, required_error: s, description: r } = n;
@@ -1330,7 +1330,7 @@ class X {
1330
1330
  const s = (r) => typeof t == "string" || typeof t > "u" ? { message: t } : typeof t == "function" ? t(r) : t;
1331
1331
  return this._refinement((r, i) => {
1332
1332
  const o = e(r), a = () => i.addIssue({
1333
- code: I.custom,
1333
+ code: D.custom,
1334
1334
  ...s(r)
1335
1335
  });
1336
1336
  return typeof Promise < "u" && o instanceof Promise ? o.then((l) => l ? !0 : (a(), !1)) : o ? !0 : (a(), !1);
@@ -1379,7 +1379,7 @@ class X {
1379
1379
  }
1380
1380
  transform(e) {
1381
1381
  return new At({
1382
- ...J(this._def),
1382
+ ...Q(this._def),
1383
1383
  schema: this,
1384
1384
  typeName: G.ZodEffects,
1385
1385
  effect: { type: "transform", transform: e }
@@ -1388,7 +1388,7 @@ class X {
1388
1388
  default(e) {
1389
1389
  const t = typeof e == "function" ? e : () => e;
1390
1390
  return new bs({
1391
- ...J(this._def),
1391
+ ...Q(this._def),
1392
1392
  innerType: this,
1393
1393
  defaultValue: t,
1394
1394
  typeName: G.ZodDefault
@@ -1398,13 +1398,13 @@ class X {
1398
1398
  return new Aa({
1399
1399
  typeName: G.ZodBranded,
1400
1400
  type: this,
1401
- ...J(this._def)
1401
+ ...Q(this._def)
1402
1402
  });
1403
1403
  }
1404
1404
  catch(e) {
1405
1405
  const t = typeof e == "function" ? e : () => e;
1406
1406
  return new Ss({
1407
- ...J(this._def),
1407
+ ...Q(this._def),
1408
1408
  innerType: this,
1409
1409
  catchValue: t,
1410
1410
  typeName: G.ZodCatch
@@ -1468,11 +1468,11 @@ function Ia(n, e) {
1468
1468
  }
1469
1469
  class qe extends X {
1470
1470
  _parse(e) {
1471
- if (this._def.coerce && (e.data = String(e.data)), this._getType(e) !== U.string) {
1471
+ if (this._def.coerce && (e.data = String(e.data)), this._getType(e) !== L.string) {
1472
1472
  const i = this._getOrReturnCtx(e);
1473
- return L(i, {
1474
- code: I.invalid_type,
1475
- expected: U.string,
1473
+ return M(i, {
1474
+ code: D.invalid_type,
1475
+ expected: L.string,
1476
1476
  received: i.parsedType
1477
1477
  }), Y;
1478
1478
  }
@@ -1480,8 +1480,8 @@ class qe extends X {
1480
1480
  let r;
1481
1481
  for (const i of this._def.checks)
1482
1482
  if (i.kind === "min")
1483
- e.data.length < i.value && (r = this._getOrReturnCtx(e, r), L(r, {
1484
- code: I.too_small,
1483
+ e.data.length < i.value && (r = this._getOrReturnCtx(e, r), M(r, {
1484
+ code: D.too_small,
1485
1485
  minimum: i.value,
1486
1486
  type: "string",
1487
1487
  inclusive: !0,
@@ -1489,8 +1489,8 @@ class qe extends X {
1489
1489
  message: i.message
1490
1490
  }), s.dirty());
1491
1491
  else if (i.kind === "max")
1492
- e.data.length > i.value && (r = this._getOrReturnCtx(e, r), L(r, {
1493
- code: I.too_big,
1492
+ e.data.length > i.value && (r = this._getOrReturnCtx(e, r), M(r, {
1493
+ code: D.too_big,
1494
1494
  maximum: i.value,
1495
1495
  type: "string",
1496
1496
  inclusive: !0,
@@ -1499,15 +1499,15 @@ class qe extends X {
1499
1499
  }), s.dirty());
1500
1500
  else if (i.kind === "length") {
1501
1501
  const o = e.data.length > i.value, a = e.data.length < i.value;
1502
- (o || a) && (r = this._getOrReturnCtx(e, r), o ? L(r, {
1503
- code: I.too_big,
1502
+ (o || a) && (r = this._getOrReturnCtx(e, r), o ? M(r, {
1503
+ code: D.too_big,
1504
1504
  maximum: i.value,
1505
1505
  type: "string",
1506
1506
  inclusive: !0,
1507
1507
  exact: !0,
1508
1508
  message: i.message
1509
- }) : a && L(r, {
1510
- code: I.too_small,
1509
+ }) : a && M(r, {
1510
+ code: D.too_small,
1511
1511
  minimum: i.value,
1512
1512
  type: "string",
1513
1513
  inclusive: !0,
@@ -1515,108 +1515,108 @@ class qe extends X {
1515
1515
  message: i.message
1516
1516
  }), s.dirty());
1517
1517
  } else if (i.kind === "email")
1518
- ga.test(e.data) || (r = this._getOrReturnCtx(e, r), L(r, {
1518
+ ga.test(e.data) || (r = this._getOrReturnCtx(e, r), M(r, {
1519
1519
  validation: "email",
1520
- code: I.invalid_string,
1520
+ code: D.invalid_string,
1521
1521
  message: i.message
1522
1522
  }), s.dirty());
1523
1523
  else if (i.kind === "emoji")
1524
- ns || (ns = new RegExp(wa, "u")), ns.test(e.data) || (r = this._getOrReturnCtx(e, r), L(r, {
1524
+ ns || (ns = new RegExp(wa, "u")), ns.test(e.data) || (r = this._getOrReturnCtx(e, r), M(r, {
1525
1525
  validation: "emoji",
1526
- code: I.invalid_string,
1526
+ code: D.invalid_string,
1527
1527
  message: i.message
1528
1528
  }), s.dirty());
1529
1529
  else if (i.kind === "uuid")
1530
- ha.test(e.data) || (r = this._getOrReturnCtx(e, r), L(r, {
1530
+ ha.test(e.data) || (r = this._getOrReturnCtx(e, r), M(r, {
1531
1531
  validation: "uuid",
1532
- code: I.invalid_string,
1532
+ code: D.invalid_string,
1533
1533
  message: i.message
1534
1534
  }), s.dirty());
1535
1535
  else if (i.kind === "nanoid")
1536
- ma.test(e.data) || (r = this._getOrReturnCtx(e, r), L(r, {
1536
+ ma.test(e.data) || (r = this._getOrReturnCtx(e, r), M(r, {
1537
1537
  validation: "nanoid",
1538
- code: I.invalid_string,
1538
+ code: D.invalid_string,
1539
1539
  message: i.message
1540
1540
  }), s.dirty());
1541
1541
  else if (i.kind === "cuid")
1542
- ua.test(e.data) || (r = this._getOrReturnCtx(e, r), L(r, {
1542
+ ua.test(e.data) || (r = this._getOrReturnCtx(e, r), M(r, {
1543
1543
  validation: "cuid",
1544
- code: I.invalid_string,
1544
+ code: D.invalid_string,
1545
1545
  message: i.message
1546
1546
  }), s.dirty());
1547
1547
  else if (i.kind === "cuid2")
1548
- da.test(e.data) || (r = this._getOrReturnCtx(e, r), L(r, {
1548
+ da.test(e.data) || (r = this._getOrReturnCtx(e, r), M(r, {
1549
1549
  validation: "cuid2",
1550
- code: I.invalid_string,
1550
+ code: D.invalid_string,
1551
1551
  message: i.message
1552
1552
  }), s.dirty());
1553
1553
  else if (i.kind === "ulid")
1554
- fa.test(e.data) || (r = this._getOrReturnCtx(e, r), L(r, {
1554
+ fa.test(e.data) || (r = this._getOrReturnCtx(e, r), M(r, {
1555
1555
  validation: "ulid",
1556
- code: I.invalid_string,
1556
+ code: D.invalid_string,
1557
1557
  message: i.message
1558
1558
  }), s.dirty());
1559
1559
  else if (i.kind === "url")
1560
1560
  try {
1561
1561
  new URL(e.data);
1562
1562
  } catch {
1563
- r = this._getOrReturnCtx(e, r), L(r, {
1563
+ r = this._getOrReturnCtx(e, r), M(r, {
1564
1564
  validation: "url",
1565
- code: I.invalid_string,
1565
+ code: D.invalid_string,
1566
1566
  message: i.message
1567
1567
  }), s.dirty();
1568
1568
  }
1569
- else i.kind === "regex" ? (i.regex.lastIndex = 0, i.regex.test(e.data) || (r = this._getOrReturnCtx(e, r), L(r, {
1569
+ else i.kind === "regex" ? (i.regex.lastIndex = 0, i.regex.test(e.data) || (r = this._getOrReturnCtx(e, r), M(r, {
1570
1570
  validation: "regex",
1571
- code: I.invalid_string,
1571
+ code: D.invalid_string,
1572
1572
  message: i.message
1573
- }), s.dirty())) : i.kind === "trim" ? e.data = e.data.trim() : i.kind === "includes" ? e.data.includes(i.value, i.position) || (r = this._getOrReturnCtx(e, r), L(r, {
1574
- code: I.invalid_string,
1573
+ }), s.dirty())) : i.kind === "trim" ? e.data = e.data.trim() : i.kind === "includes" ? e.data.includes(i.value, i.position) || (r = this._getOrReturnCtx(e, r), M(r, {
1574
+ code: D.invalid_string,
1575
1575
  validation: { includes: i.value, position: i.position },
1576
1576
  message: i.message
1577
- }), s.dirty()) : i.kind === "toLowerCase" ? e.data = e.data.toLowerCase() : i.kind === "toUpperCase" ? e.data = e.data.toUpperCase() : i.kind === "startsWith" ? e.data.startsWith(i.value) || (r = this._getOrReturnCtx(e, r), L(r, {
1578
- code: I.invalid_string,
1577
+ }), s.dirty()) : i.kind === "toLowerCase" ? e.data = e.data.toLowerCase() : i.kind === "toUpperCase" ? e.data = e.data.toUpperCase() : i.kind === "startsWith" ? e.data.startsWith(i.value) || (r = this._getOrReturnCtx(e, r), M(r, {
1578
+ code: D.invalid_string,
1579
1579
  validation: { startsWith: i.value },
1580
1580
  message: i.message
1581
- }), s.dirty()) : i.kind === "endsWith" ? e.data.endsWith(i.value) || (r = this._getOrReturnCtx(e, r), L(r, {
1582
- code: I.invalid_string,
1581
+ }), s.dirty()) : i.kind === "endsWith" ? e.data.endsWith(i.value) || (r = this._getOrReturnCtx(e, r), M(r, {
1582
+ code: D.invalid_string,
1583
1583
  validation: { endsWith: i.value },
1584
1584
  message: i.message
1585
- }), s.dirty()) : i.kind === "datetime" ? Ra(i).test(e.data) || (r = this._getOrReturnCtx(e, r), L(r, {
1586
- code: I.invalid_string,
1585
+ }), s.dirty()) : i.kind === "datetime" ? Ra(i).test(e.data) || (r = this._getOrReturnCtx(e, r), M(r, {
1586
+ code: D.invalid_string,
1587
1587
  validation: "datetime",
1588
1588
  message: i.message
1589
- }), s.dirty()) : i.kind === "date" ? Sa.test(e.data) || (r = this._getOrReturnCtx(e, r), L(r, {
1590
- code: I.invalid_string,
1589
+ }), s.dirty()) : i.kind === "date" ? Sa.test(e.data) || (r = this._getOrReturnCtx(e, r), M(r, {
1590
+ code: D.invalid_string,
1591
1591
  validation: "date",
1592
1592
  message: i.message
1593
- }), s.dirty()) : i.kind === "time" ? Ta(i).test(e.data) || (r = this._getOrReturnCtx(e, r), L(r, {
1594
- code: I.invalid_string,
1593
+ }), s.dirty()) : i.kind === "time" ? Ta(i).test(e.data) || (r = this._getOrReturnCtx(e, r), M(r, {
1594
+ code: D.invalid_string,
1595
1595
  validation: "time",
1596
1596
  message: i.message
1597
- }), s.dirty()) : i.kind === "duration" ? ya.test(e.data) || (r = this._getOrReturnCtx(e, r), L(r, {
1597
+ }), s.dirty()) : i.kind === "duration" ? ya.test(e.data) || (r = this._getOrReturnCtx(e, r), M(r, {
1598
1598
  validation: "duration",
1599
- code: I.invalid_string,
1599
+ code: D.invalid_string,
1600
1600
  message: i.message
1601
- }), s.dirty()) : i.kind === "ip" ? Na(e.data, i.version) || (r = this._getOrReturnCtx(e, r), L(r, {
1601
+ }), s.dirty()) : i.kind === "ip" ? Na(e.data, i.version) || (r = this._getOrReturnCtx(e, r), M(r, {
1602
1602
  validation: "ip",
1603
- code: I.invalid_string,
1603
+ code: D.invalid_string,
1604
1604
  message: i.message
1605
- }), s.dirty()) : i.kind === "jwt" ? xa(e.data, i.alg) || (r = this._getOrReturnCtx(e, r), L(r, {
1605
+ }), s.dirty()) : i.kind === "jwt" ? xa(e.data, i.alg) || (r = this._getOrReturnCtx(e, r), M(r, {
1606
1606
  validation: "jwt",
1607
- code: I.invalid_string,
1607
+ code: D.invalid_string,
1608
1608
  message: i.message
1609
- }), s.dirty()) : i.kind === "cidr" ? Ia(e.data, i.version) || (r = this._getOrReturnCtx(e, r), L(r, {
1609
+ }), s.dirty()) : i.kind === "cidr" ? Ia(e.data, i.version) || (r = this._getOrReturnCtx(e, r), M(r, {
1610
1610
  validation: "cidr",
1611
- code: I.invalid_string,
1611
+ code: D.invalid_string,
1612
1612
  message: i.message
1613
- }), s.dirty()) : i.kind === "base64" ? ka.test(e.data) || (r = this._getOrReturnCtx(e, r), L(r, {
1613
+ }), s.dirty()) : i.kind === "base64" ? ka.test(e.data) || (r = this._getOrReturnCtx(e, r), M(r, {
1614
1614
  validation: "base64",
1615
- code: I.invalid_string,
1615
+ code: D.invalid_string,
1616
1616
  message: i.message
1617
- }), s.dirty()) : i.kind === "base64url" ? ba.test(e.data) || (r = this._getOrReturnCtx(e, r), L(r, {
1617
+ }), s.dirty()) : i.kind === "base64url" ? ba.test(e.data) || (r = this._getOrReturnCtx(e, r), M(r, {
1618
1618
  validation: "base64url",
1619
- code: I.invalid_string,
1619
+ code: D.invalid_string,
1620
1620
  message: i.message
1621
1621
  }), s.dirty()) : te.assertNever(i);
1622
1622
  return { status: s.value, value: e.data };
@@ -1624,8 +1624,8 @@ class qe extends X {
1624
1624
  _regex(e, t, s) {
1625
1625
  return this.refinement((r) => e.test(r), {
1626
1626
  validation: t,
1627
- code: I.invalid_string,
1628
- ...z.errToObj(s)
1627
+ code: D.invalid_string,
1628
+ ...Z.errToObj(s)
1629
1629
  });
1630
1630
  }
1631
1631
  _addCheck(e) {
@@ -1635,46 +1635,46 @@ class qe extends X {
1635
1635
  });
1636
1636
  }
1637
1637
  email(e) {
1638
- return this._addCheck({ kind: "email", ...z.errToObj(e) });
1638
+ return this._addCheck({ kind: "email", ...Z.errToObj(e) });
1639
1639
  }
1640
1640
  url(e) {
1641
- return this._addCheck({ kind: "url", ...z.errToObj(e) });
1641
+ return this._addCheck({ kind: "url", ...Z.errToObj(e) });
1642
1642
  }
1643
1643
  emoji(e) {
1644
- return this._addCheck({ kind: "emoji", ...z.errToObj(e) });
1644
+ return this._addCheck({ kind: "emoji", ...Z.errToObj(e) });
1645
1645
  }
1646
1646
  uuid(e) {
1647
- return this._addCheck({ kind: "uuid", ...z.errToObj(e) });
1647
+ return this._addCheck({ kind: "uuid", ...Z.errToObj(e) });
1648
1648
  }
1649
1649
  nanoid(e) {
1650
- return this._addCheck({ kind: "nanoid", ...z.errToObj(e) });
1650
+ return this._addCheck({ kind: "nanoid", ...Z.errToObj(e) });
1651
1651
  }
1652
1652
  cuid(e) {
1653
- return this._addCheck({ kind: "cuid", ...z.errToObj(e) });
1653
+ return this._addCheck({ kind: "cuid", ...Z.errToObj(e) });
1654
1654
  }
1655
1655
  cuid2(e) {
1656
- return this._addCheck({ kind: "cuid2", ...z.errToObj(e) });
1656
+ return this._addCheck({ kind: "cuid2", ...Z.errToObj(e) });
1657
1657
  }
1658
1658
  ulid(e) {
1659
- return this._addCheck({ kind: "ulid", ...z.errToObj(e) });
1659
+ return this._addCheck({ kind: "ulid", ...Z.errToObj(e) });
1660
1660
  }
1661
1661
  base64(e) {
1662
- return this._addCheck({ kind: "base64", ...z.errToObj(e) });
1662
+ return this._addCheck({ kind: "base64", ...Z.errToObj(e) });
1663
1663
  }
1664
1664
  base64url(e) {
1665
1665
  return this._addCheck({
1666
1666
  kind: "base64url",
1667
- ...z.errToObj(e)
1667
+ ...Z.errToObj(e)
1668
1668
  });
1669
1669
  }
1670
1670
  jwt(e) {
1671
- return this._addCheck({ kind: "jwt", ...z.errToObj(e) });
1671
+ return this._addCheck({ kind: "jwt", ...Z.errToObj(e) });
1672
1672
  }
1673
1673
  ip(e) {
1674
- return this._addCheck({ kind: "ip", ...z.errToObj(e) });
1674
+ return this._addCheck({ kind: "ip", ...Z.errToObj(e) });
1675
1675
  }
1676
1676
  cidr(e) {
1677
- return this._addCheck({ kind: "cidr", ...z.errToObj(e) });
1677
+ return this._addCheck({ kind: "cidr", ...Z.errToObj(e) });
1678
1678
  }
1679
1679
  datetime(e) {
1680
1680
  return typeof e == "string" ? this._addCheck({
@@ -1688,7 +1688,7 @@ class qe extends X {
1688
1688
  precision: typeof e?.precision > "u" ? null : e?.precision,
1689
1689
  offset: e?.offset ?? !1,
1690
1690
  local: e?.local ?? !1,
1691
- ...z.errToObj(e?.message)
1691
+ ...Z.errToObj(e?.message)
1692
1692
  });
1693
1693
  }
1694
1694
  date(e) {
@@ -1702,17 +1702,17 @@ class qe extends X {
1702
1702
  }) : this._addCheck({
1703
1703
  kind: "time",
1704
1704
  precision: typeof e?.precision > "u" ? null : e?.precision,
1705
- ...z.errToObj(e?.message)
1705
+ ...Z.errToObj(e?.message)
1706
1706
  });
1707
1707
  }
1708
1708
  duration(e) {
1709
- return this._addCheck({ kind: "duration", ...z.errToObj(e) });
1709
+ return this._addCheck({ kind: "duration", ...Z.errToObj(e) });
1710
1710
  }
1711
1711
  regex(e, t) {
1712
1712
  return this._addCheck({
1713
1713
  kind: "regex",
1714
1714
  regex: e,
1715
- ...z.errToObj(t)
1715
+ ...Z.errToObj(t)
1716
1716
  });
1717
1717
  }
1718
1718
  includes(e, t) {
@@ -1720,49 +1720,49 @@ class qe extends X {
1720
1720
  kind: "includes",
1721
1721
  value: e,
1722
1722
  position: t?.position,
1723
- ...z.errToObj(t?.message)
1723
+ ...Z.errToObj(t?.message)
1724
1724
  });
1725
1725
  }
1726
1726
  startsWith(e, t) {
1727
1727
  return this._addCheck({
1728
1728
  kind: "startsWith",
1729
1729
  value: e,
1730
- ...z.errToObj(t)
1730
+ ...Z.errToObj(t)
1731
1731
  });
1732
1732
  }
1733
1733
  endsWith(e, t) {
1734
1734
  return this._addCheck({
1735
1735
  kind: "endsWith",
1736
1736
  value: e,
1737
- ...z.errToObj(t)
1737
+ ...Z.errToObj(t)
1738
1738
  });
1739
1739
  }
1740
1740
  min(e, t) {
1741
1741
  return this._addCheck({
1742
1742
  kind: "min",
1743
1743
  value: e,
1744
- ...z.errToObj(t)
1744
+ ...Z.errToObj(t)
1745
1745
  });
1746
1746
  }
1747
1747
  max(e, t) {
1748
1748
  return this._addCheck({
1749
1749
  kind: "max",
1750
1750
  value: e,
1751
- ...z.errToObj(t)
1751
+ ...Z.errToObj(t)
1752
1752
  });
1753
1753
  }
1754
1754
  length(e, t) {
1755
1755
  return this._addCheck({
1756
1756
  kind: "length",
1757
1757
  value: e,
1758
- ...z.errToObj(t)
1758
+ ...Z.errToObj(t)
1759
1759
  });
1760
1760
  }
1761
1761
  /**
1762
1762
  * Equivalent to `.min(1)`
1763
1763
  */
1764
1764
  nonempty(e) {
1765
- return this.min(1, z.errToObj(e));
1765
+ return this.min(1, Z.errToObj(e));
1766
1766
  }
1767
1767
  trim() {
1768
1768
  return new qe({
@@ -1847,7 +1847,7 @@ qe.create = (n) => new qe({
1847
1847
  checks: [],
1848
1848
  typeName: G.ZodString,
1849
1849
  coerce: n?.coerce ?? !1,
1850
- ...J(n)
1850
+ ...Q(n)
1851
1851
  });
1852
1852
  function Da(n, e) {
1853
1853
  const t = (n.toString().split(".")[1] || "").length, s = (e.toString().split(".")[1] || "").length, r = t > s ? t : s, i = Number.parseInt(n.toFixed(r).replace(".", "")), o = Number.parseInt(e.toFixed(r).replace(".", ""));
@@ -1858,57 +1858,57 @@ class It extends X {
1858
1858
  super(...arguments), this.min = this.gte, this.max = this.lte, this.step = this.multipleOf;
1859
1859
  }
1860
1860
  _parse(e) {
1861
- if (this._def.coerce && (e.data = Number(e.data)), this._getType(e) !== U.number) {
1861
+ if (this._def.coerce && (e.data = Number(e.data)), this._getType(e) !== L.number) {
1862
1862
  const i = this._getOrReturnCtx(e);
1863
- return L(i, {
1864
- code: I.invalid_type,
1865
- expected: U.number,
1863
+ return M(i, {
1864
+ code: D.invalid_type,
1865
+ expected: L.number,
1866
1866
  received: i.parsedType
1867
1867
  }), Y;
1868
1868
  }
1869
1869
  let s;
1870
1870
  const r = new ve();
1871
1871
  for (const i of this._def.checks)
1872
- i.kind === "int" ? te.isInteger(e.data) || (s = this._getOrReturnCtx(e, s), L(s, {
1873
- code: I.invalid_type,
1872
+ i.kind === "int" ? te.isInteger(e.data) || (s = this._getOrReturnCtx(e, s), M(s, {
1873
+ code: D.invalid_type,
1874
1874
  expected: "integer",
1875
1875
  received: "float",
1876
1876
  message: i.message
1877
- }), r.dirty()) : i.kind === "min" ? (i.inclusive ? e.data < i.value : e.data <= i.value) && (s = this._getOrReturnCtx(e, s), L(s, {
1878
- code: I.too_small,
1877
+ }), r.dirty()) : i.kind === "min" ? (i.inclusive ? e.data < i.value : e.data <= i.value) && (s = this._getOrReturnCtx(e, s), M(s, {
1878
+ code: D.too_small,
1879
1879
  minimum: i.value,
1880
1880
  type: "number",
1881
1881
  inclusive: i.inclusive,
1882
1882
  exact: !1,
1883
1883
  message: i.message
1884
- }), r.dirty()) : i.kind === "max" ? (i.inclusive ? e.data > i.value : e.data >= i.value) && (s = this._getOrReturnCtx(e, s), L(s, {
1885
- code: I.too_big,
1884
+ }), r.dirty()) : i.kind === "max" ? (i.inclusive ? e.data > i.value : e.data >= i.value) && (s = this._getOrReturnCtx(e, s), M(s, {
1885
+ code: D.too_big,
1886
1886
  maximum: i.value,
1887
1887
  type: "number",
1888
1888
  inclusive: i.inclusive,
1889
1889
  exact: !1,
1890
1890
  message: i.message
1891
- }), r.dirty()) : i.kind === "multipleOf" ? Da(e.data, i.value) !== 0 && (s = this._getOrReturnCtx(e, s), L(s, {
1892
- code: I.not_multiple_of,
1891
+ }), r.dirty()) : i.kind === "multipleOf" ? Da(e.data, i.value) !== 0 && (s = this._getOrReturnCtx(e, s), M(s, {
1892
+ code: D.not_multiple_of,
1893
1893
  multipleOf: i.value,
1894
1894
  message: i.message
1895
- }), r.dirty()) : i.kind === "finite" ? Number.isFinite(e.data) || (s = this._getOrReturnCtx(e, s), L(s, {
1896
- code: I.not_finite,
1895
+ }), r.dirty()) : i.kind === "finite" ? Number.isFinite(e.data) || (s = this._getOrReturnCtx(e, s), M(s, {
1896
+ code: D.not_finite,
1897
1897
  message: i.message
1898
1898
  }), r.dirty()) : te.assertNever(i);
1899
1899
  return { status: r.value, value: e.data };
1900
1900
  }
1901
1901
  gte(e, t) {
1902
- return this.setLimit("min", e, !0, z.toString(t));
1902
+ return this.setLimit("min", e, !0, Z.toString(t));
1903
1903
  }
1904
1904
  gt(e, t) {
1905
- return this.setLimit("min", e, !1, z.toString(t));
1905
+ return this.setLimit("min", e, !1, Z.toString(t));
1906
1906
  }
1907
1907
  lte(e, t) {
1908
- return this.setLimit("max", e, !0, z.toString(t));
1908
+ return this.setLimit("max", e, !0, Z.toString(t));
1909
1909
  }
1910
1910
  lt(e, t) {
1911
- return this.setLimit("max", e, !1, z.toString(t));
1911
+ return this.setLimit("max", e, !1, Z.toString(t));
1912
1912
  }
1913
1913
  setLimit(e, t, s, r) {
1914
1914
  return new It({
@@ -1919,7 +1919,7 @@ class It extends X {
1919
1919
  kind: e,
1920
1920
  value: t,
1921
1921
  inclusive: s,
1922
- message: z.toString(r)
1922
+ message: Z.toString(r)
1923
1923
  }
1924
1924
  ]
1925
1925
  });
@@ -1933,7 +1933,7 @@ class It extends X {
1933
1933
  int(e) {
1934
1934
  return this._addCheck({
1935
1935
  kind: "int",
1936
- message: z.toString(e)
1936
+ message: Z.toString(e)
1937
1937
  });
1938
1938
  }
1939
1939
  positive(e) {
@@ -1941,7 +1941,7 @@ class It extends X {
1941
1941
  kind: "min",
1942
1942
  value: 0,
1943
1943
  inclusive: !1,
1944
- message: z.toString(e)
1944
+ message: Z.toString(e)
1945
1945
  });
1946
1946
  }
1947
1947
  negative(e) {
@@ -1949,7 +1949,7 @@ class It extends X {
1949
1949
  kind: "max",
1950
1950
  value: 0,
1951
1951
  inclusive: !1,
1952
- message: z.toString(e)
1952
+ message: Z.toString(e)
1953
1953
  });
1954
1954
  }
1955
1955
  nonpositive(e) {
@@ -1957,7 +1957,7 @@ class It extends X {
1957
1957
  kind: "max",
1958
1958
  value: 0,
1959
1959
  inclusive: !0,
1960
- message: z.toString(e)
1960
+ message: Z.toString(e)
1961
1961
  });
1962
1962
  }
1963
1963
  nonnegative(e) {
@@ -1965,20 +1965,20 @@ class It extends X {
1965
1965
  kind: "min",
1966
1966
  value: 0,
1967
1967
  inclusive: !0,
1968
- message: z.toString(e)
1968
+ message: Z.toString(e)
1969
1969
  });
1970
1970
  }
1971
1971
  multipleOf(e, t) {
1972
1972
  return this._addCheck({
1973
1973
  kind: "multipleOf",
1974
1974
  value: e,
1975
- message: z.toString(t)
1975
+ message: Z.toString(t)
1976
1976
  });
1977
1977
  }
1978
1978
  finite(e) {
1979
1979
  return this._addCheck({
1980
1980
  kind: "finite",
1981
- message: z.toString(e)
1981
+ message: Z.toString(e)
1982
1982
  });
1983
1983
  }
1984
1984
  safe(e) {
@@ -1986,12 +1986,12 @@ class It extends X {
1986
1986
  kind: "min",
1987
1987
  inclusive: !0,
1988
1988
  value: Number.MIN_SAFE_INTEGER,
1989
- message: z.toString(e)
1989
+ message: Z.toString(e)
1990
1990
  })._addCheck({
1991
1991
  kind: "max",
1992
1992
  inclusive: !0,
1993
1993
  value: Number.MAX_SAFE_INTEGER,
1994
- message: z.toString(e)
1994
+ message: Z.toString(e)
1995
1995
  });
1996
1996
  }
1997
1997
  get minValue() {
@@ -2023,7 +2023,7 @@ It.create = (n) => new It({
2023
2023
  checks: [],
2024
2024
  typeName: G.ZodNumber,
2025
2025
  coerce: n?.coerce || !1,
2026
- ...J(n)
2026
+ ...Q(n)
2027
2027
  });
2028
2028
  class en extends X {
2029
2029
  constructor() {
@@ -2036,25 +2036,25 @@ class en extends X {
2036
2036
  } catch {
2037
2037
  return this._getInvalidInput(e);
2038
2038
  }
2039
- if (this._getType(e) !== U.bigint)
2039
+ if (this._getType(e) !== L.bigint)
2040
2040
  return this._getInvalidInput(e);
2041
2041
  let s;
2042
2042
  const r = new ve();
2043
2043
  for (const i of this._def.checks)
2044
- i.kind === "min" ? (i.inclusive ? e.data < i.value : e.data <= i.value) && (s = this._getOrReturnCtx(e, s), L(s, {
2045
- code: I.too_small,
2044
+ i.kind === "min" ? (i.inclusive ? e.data < i.value : e.data <= i.value) && (s = this._getOrReturnCtx(e, s), M(s, {
2045
+ code: D.too_small,
2046
2046
  type: "bigint",
2047
2047
  minimum: i.value,
2048
2048
  inclusive: i.inclusive,
2049
2049
  message: i.message
2050
- }), r.dirty()) : i.kind === "max" ? (i.inclusive ? e.data > i.value : e.data >= i.value) && (s = this._getOrReturnCtx(e, s), L(s, {
2051
- code: I.too_big,
2050
+ }), r.dirty()) : i.kind === "max" ? (i.inclusive ? e.data > i.value : e.data >= i.value) && (s = this._getOrReturnCtx(e, s), M(s, {
2051
+ code: D.too_big,
2052
2052
  type: "bigint",
2053
2053
  maximum: i.value,
2054
2054
  inclusive: i.inclusive,
2055
2055
  message: i.message
2056
- }), r.dirty()) : i.kind === "multipleOf" ? e.data % i.value !== BigInt(0) && (s = this._getOrReturnCtx(e, s), L(s, {
2057
- code: I.not_multiple_of,
2056
+ }), r.dirty()) : i.kind === "multipleOf" ? e.data % i.value !== BigInt(0) && (s = this._getOrReturnCtx(e, s), M(s, {
2057
+ code: D.not_multiple_of,
2058
2058
  multipleOf: i.value,
2059
2059
  message: i.message
2060
2060
  }), r.dirty()) : te.assertNever(i);
@@ -2062,23 +2062,23 @@ class en extends X {
2062
2062
  }
2063
2063
  _getInvalidInput(e) {
2064
2064
  const t = this._getOrReturnCtx(e);
2065
- return L(t, {
2066
- code: I.invalid_type,
2067
- expected: U.bigint,
2065
+ return M(t, {
2066
+ code: D.invalid_type,
2067
+ expected: L.bigint,
2068
2068
  received: t.parsedType
2069
2069
  }), Y;
2070
2070
  }
2071
2071
  gte(e, t) {
2072
- return this.setLimit("min", e, !0, z.toString(t));
2072
+ return this.setLimit("min", e, !0, Z.toString(t));
2073
2073
  }
2074
2074
  gt(e, t) {
2075
- return this.setLimit("min", e, !1, z.toString(t));
2075
+ return this.setLimit("min", e, !1, Z.toString(t));
2076
2076
  }
2077
2077
  lte(e, t) {
2078
- return this.setLimit("max", e, !0, z.toString(t));
2078
+ return this.setLimit("max", e, !0, Z.toString(t));
2079
2079
  }
2080
2080
  lt(e, t) {
2081
- return this.setLimit("max", e, !1, z.toString(t));
2081
+ return this.setLimit("max", e, !1, Z.toString(t));
2082
2082
  }
2083
2083
  setLimit(e, t, s, r) {
2084
2084
  return new en({
@@ -2089,7 +2089,7 @@ class en extends X {
2089
2089
  kind: e,
2090
2090
  value: t,
2091
2091
  inclusive: s,
2092
- message: z.toString(r)
2092
+ message: Z.toString(r)
2093
2093
  }
2094
2094
  ]
2095
2095
  });
@@ -2105,7 +2105,7 @@ class en extends X {
2105
2105
  kind: "min",
2106
2106
  value: BigInt(0),
2107
2107
  inclusive: !1,
2108
- message: z.toString(e)
2108
+ message: Z.toString(e)
2109
2109
  });
2110
2110
  }
2111
2111
  negative(e) {
@@ -2113,7 +2113,7 @@ class en extends X {
2113
2113
  kind: "max",
2114
2114
  value: BigInt(0),
2115
2115
  inclusive: !1,
2116
- message: z.toString(e)
2116
+ message: Z.toString(e)
2117
2117
  });
2118
2118
  }
2119
2119
  nonpositive(e) {
@@ -2121,7 +2121,7 @@ class en extends X {
2121
2121
  kind: "max",
2122
2122
  value: BigInt(0),
2123
2123
  inclusive: !0,
2124
- message: z.toString(e)
2124
+ message: Z.toString(e)
2125
2125
  });
2126
2126
  }
2127
2127
  nonnegative(e) {
@@ -2129,14 +2129,14 @@ class en extends X {
2129
2129
  kind: "min",
2130
2130
  value: BigInt(0),
2131
2131
  inclusive: !0,
2132
- message: z.toString(e)
2132
+ message: Z.toString(e)
2133
2133
  });
2134
2134
  }
2135
2135
  multipleOf(e, t) {
2136
2136
  return this._addCheck({
2137
2137
  kind: "multipleOf",
2138
2138
  value: e,
2139
- message: z.toString(t)
2139
+ message: Z.toString(t)
2140
2140
  });
2141
2141
  }
2142
2142
  get minValue() {
@@ -2156,15 +2156,15 @@ en.create = (n) => new en({
2156
2156
  checks: [],
2157
2157
  typeName: G.ZodBigInt,
2158
2158
  coerce: n?.coerce ?? !1,
2159
- ...J(n)
2159
+ ...Q(n)
2160
2160
  });
2161
2161
  class _s extends X {
2162
2162
  _parse(e) {
2163
- if (this._def.coerce && (e.data = !!e.data), this._getType(e) !== U.boolean) {
2163
+ if (this._def.coerce && (e.data = !!e.data), this._getType(e) !== L.boolean) {
2164
2164
  const s = this._getOrReturnCtx(e);
2165
- return L(s, {
2166
- code: I.invalid_type,
2167
- expected: U.boolean,
2165
+ return M(s, {
2166
+ code: D.invalid_type,
2167
+ expected: L.boolean,
2168
2168
  received: s.parsedType
2169
2169
  }), Y;
2170
2170
  }
@@ -2174,36 +2174,36 @@ class _s extends X {
2174
2174
  _s.create = (n) => new _s({
2175
2175
  typeName: G.ZodBoolean,
2176
2176
  coerce: n?.coerce || !1,
2177
- ...J(n)
2177
+ ...Q(n)
2178
2178
  });
2179
2179
  class xn extends X {
2180
2180
  _parse(e) {
2181
- if (this._def.coerce && (e.data = new Date(e.data)), this._getType(e) !== U.date) {
2181
+ if (this._def.coerce && (e.data = new Date(e.data)), this._getType(e) !== L.date) {
2182
2182
  const i = this._getOrReturnCtx(e);
2183
- return L(i, {
2184
- code: I.invalid_type,
2185
- expected: U.date,
2183
+ return M(i, {
2184
+ code: D.invalid_type,
2185
+ expected: L.date,
2186
2186
  received: i.parsedType
2187
2187
  }), Y;
2188
2188
  }
2189
2189
  if (Number.isNaN(e.data.getTime())) {
2190
2190
  const i = this._getOrReturnCtx(e);
2191
- return L(i, {
2192
- code: I.invalid_date
2191
+ return M(i, {
2192
+ code: D.invalid_date
2193
2193
  }), Y;
2194
2194
  }
2195
2195
  const s = new ve();
2196
2196
  let r;
2197
2197
  for (const i of this._def.checks)
2198
- i.kind === "min" ? e.data.getTime() < i.value && (r = this._getOrReturnCtx(e, r), L(r, {
2199
- code: I.too_small,
2198
+ i.kind === "min" ? e.data.getTime() < i.value && (r = this._getOrReturnCtx(e, r), M(r, {
2199
+ code: D.too_small,
2200
2200
  message: i.message,
2201
2201
  inclusive: !0,
2202
2202
  exact: !1,
2203
2203
  minimum: i.value,
2204
2204
  type: "date"
2205
- }), s.dirty()) : i.kind === "max" ? e.data.getTime() > i.value && (r = this._getOrReturnCtx(e, r), L(r, {
2206
- code: I.too_big,
2205
+ }), s.dirty()) : i.kind === "max" ? e.data.getTime() > i.value && (r = this._getOrReturnCtx(e, r), M(r, {
2206
+ code: D.too_big,
2207
2207
  message: i.message,
2208
2208
  inclusive: !0,
2209
2209
  exact: !1,
@@ -2225,14 +2225,14 @@ class xn extends X {
2225
2225
  return this._addCheck({
2226
2226
  kind: "min",
2227
2227
  value: e.getTime(),
2228
- message: z.toString(t)
2228
+ message: Z.toString(t)
2229
2229
  });
2230
2230
  }
2231
2231
  max(e, t) {
2232
2232
  return this._addCheck({
2233
2233
  kind: "max",
2234
2234
  value: e.getTime(),
2235
- message: z.toString(t)
2235
+ message: Z.toString(t)
2236
2236
  });
2237
2237
  }
2238
2238
  get minDate() {
@@ -2252,15 +2252,15 @@ xn.create = (n) => new xn({
2252
2252
  checks: [],
2253
2253
  coerce: n?.coerce || !1,
2254
2254
  typeName: G.ZodDate,
2255
- ...J(n)
2255
+ ...Q(n)
2256
2256
  });
2257
2257
  class dr extends X {
2258
2258
  _parse(e) {
2259
- if (this._getType(e) !== U.symbol) {
2259
+ if (this._getType(e) !== L.symbol) {
2260
2260
  const s = this._getOrReturnCtx(e);
2261
- return L(s, {
2262
- code: I.invalid_type,
2263
- expected: U.symbol,
2261
+ return M(s, {
2262
+ code: D.invalid_type,
2263
+ expected: L.symbol,
2264
2264
  received: s.parsedType
2265
2265
  }), Y;
2266
2266
  }
@@ -2269,15 +2269,15 @@ class dr extends X {
2269
2269
  }
2270
2270
  dr.create = (n) => new dr({
2271
2271
  typeName: G.ZodSymbol,
2272
- ...J(n)
2272
+ ...Q(n)
2273
2273
  });
2274
2274
  class Es extends X {
2275
2275
  _parse(e) {
2276
- if (this._getType(e) !== U.undefined) {
2276
+ if (this._getType(e) !== L.undefined) {
2277
2277
  const s = this._getOrReturnCtx(e);
2278
- return L(s, {
2279
- code: I.invalid_type,
2280
- expected: U.undefined,
2278
+ return M(s, {
2279
+ code: D.invalid_type,
2280
+ expected: L.undefined,
2281
2281
  received: s.parsedType
2282
2282
  }), Y;
2283
2283
  }
@@ -2286,15 +2286,15 @@ class Es extends X {
2286
2286
  }
2287
2287
  Es.create = (n) => new Es({
2288
2288
  typeName: G.ZodUndefined,
2289
- ...J(n)
2289
+ ...Q(n)
2290
2290
  });
2291
2291
  class fr extends X {
2292
2292
  _parse(e) {
2293
- if (this._getType(e) !== U.null) {
2293
+ if (this._getType(e) !== L.null) {
2294
2294
  const s = this._getOrReturnCtx(e);
2295
- return L(s, {
2296
- code: I.invalid_type,
2297
- expected: U.null,
2295
+ return M(s, {
2296
+ code: D.invalid_type,
2297
+ expected: L.null,
2298
2298
  received: s.parsedType
2299
2299
  }), Y;
2300
2300
  }
@@ -2303,7 +2303,7 @@ class fr extends X {
2303
2303
  }
2304
2304
  fr.create = (n) => new fr({
2305
2305
  typeName: G.ZodNull,
2306
- ...J(n)
2306
+ ...Q(n)
2307
2307
  });
2308
2308
  class vs extends X {
2309
2309
  constructor() {
@@ -2315,7 +2315,7 @@ class vs extends X {
2315
2315
  }
2316
2316
  vs.create = (n) => new vs({
2317
2317
  typeName: G.ZodAny,
2318
- ...J(n)
2318
+ ...Q(n)
2319
2319
  });
2320
2320
  class hr extends X {
2321
2321
  constructor() {
@@ -2327,29 +2327,29 @@ class hr extends X {
2327
2327
  }
2328
2328
  hr.create = (n) => new hr({
2329
2329
  typeName: G.ZodUnknown,
2330
- ...J(n)
2330
+ ...Q(n)
2331
2331
  });
2332
2332
  class ot extends X {
2333
2333
  _parse(e) {
2334
2334
  const t = this._getOrReturnCtx(e);
2335
- return L(t, {
2336
- code: I.invalid_type,
2337
- expected: U.never,
2335
+ return M(t, {
2336
+ code: D.invalid_type,
2337
+ expected: L.never,
2338
2338
  received: t.parsedType
2339
2339
  }), Y;
2340
2340
  }
2341
2341
  }
2342
2342
  ot.create = (n) => new ot({
2343
2343
  typeName: G.ZodNever,
2344
- ...J(n)
2344
+ ...Q(n)
2345
2345
  });
2346
2346
  class mr extends X {
2347
2347
  _parse(e) {
2348
- if (this._getType(e) !== U.undefined) {
2348
+ if (this._getType(e) !== L.undefined) {
2349
2349
  const s = this._getOrReturnCtx(e);
2350
- return L(s, {
2351
- code: I.invalid_type,
2352
- expected: U.void,
2350
+ return M(s, {
2351
+ code: D.invalid_type,
2352
+ expected: L.void,
2353
2353
  received: s.parsedType
2354
2354
  }), Y;
2355
2355
  }
@@ -2358,21 +2358,21 @@ class mr extends X {
2358
2358
  }
2359
2359
  mr.create = (n) => new mr({
2360
2360
  typeName: G.ZodVoid,
2361
- ...J(n)
2361
+ ...Q(n)
2362
2362
  });
2363
2363
  class Ue extends X {
2364
2364
  _parse(e) {
2365
2365
  const { ctx: t, status: s } = this._processInputParams(e), r = this._def;
2366
- if (t.parsedType !== U.array)
2367
- return L(t, {
2368
- code: I.invalid_type,
2369
- expected: U.array,
2366
+ if (t.parsedType !== L.array)
2367
+ return M(t, {
2368
+ code: D.invalid_type,
2369
+ expected: L.array,
2370
2370
  received: t.parsedType
2371
2371
  }), Y;
2372
2372
  if (r.exactLength !== null) {
2373
2373
  const o = t.data.length > r.exactLength.value, a = t.data.length < r.exactLength.value;
2374
- (o || a) && (L(t, {
2375
- code: o ? I.too_big : I.too_small,
2374
+ (o || a) && (M(t, {
2375
+ code: o ? D.too_big : D.too_small,
2376
2376
  minimum: a ? r.exactLength.value : void 0,
2377
2377
  maximum: o ? r.exactLength.value : void 0,
2378
2378
  type: "array",
@@ -2381,15 +2381,15 @@ class Ue extends X {
2381
2381
  message: r.exactLength.message
2382
2382
  }), s.dirty());
2383
2383
  }
2384
- if (r.minLength !== null && t.data.length < r.minLength.value && (L(t, {
2385
- code: I.too_small,
2384
+ if (r.minLength !== null && t.data.length < r.minLength.value && (M(t, {
2385
+ code: D.too_small,
2386
2386
  minimum: r.minLength.value,
2387
2387
  type: "array",
2388
2388
  inclusive: !0,
2389
2389
  exact: !1,
2390
2390
  message: r.minLength.message
2391
- }), s.dirty()), r.maxLength !== null && t.data.length > r.maxLength.value && (L(t, {
2392
- code: I.too_big,
2391
+ }), s.dirty()), r.maxLength !== null && t.data.length > r.maxLength.value && (M(t, {
2392
+ code: D.too_big,
2393
2393
  maximum: r.maxLength.value,
2394
2394
  type: "array",
2395
2395
  inclusive: !0,
@@ -2406,19 +2406,19 @@ class Ue extends X {
2406
2406
  min(e, t) {
2407
2407
  return new Ue({
2408
2408
  ...this._def,
2409
- minLength: { value: e, message: z.toString(t) }
2409
+ minLength: { value: e, message: Z.toString(t) }
2410
2410
  });
2411
2411
  }
2412
2412
  max(e, t) {
2413
2413
  return new Ue({
2414
2414
  ...this._def,
2415
- maxLength: { value: e, message: z.toString(t) }
2415
+ maxLength: { value: e, message: Z.toString(t) }
2416
2416
  });
2417
2417
  }
2418
2418
  length(e, t) {
2419
2419
  return new Ue({
2420
2420
  ...this._def,
2421
- exactLength: { value: e, message: z.toString(t) }
2421
+ exactLength: { value: e, message: Z.toString(t) }
2422
2422
  });
2423
2423
  }
2424
2424
  nonempty(e) {
@@ -2431,7 +2431,7 @@ Ue.create = (n, e) => new Ue({
2431
2431
  maxLength: null,
2432
2432
  exactLength: null,
2433
2433
  typeName: G.ZodArray,
2434
- ...J(e)
2434
+ ...Q(e)
2435
2435
  });
2436
2436
  function bt(n) {
2437
2437
  if (n instanceof fe) {
@@ -2460,11 +2460,11 @@ class fe extends X {
2460
2460
  return this._cached = { shape: e, keys: t }, this._cached;
2461
2461
  }
2462
2462
  _parse(e) {
2463
- if (this._getType(e) !== U.object) {
2463
+ if (this._getType(e) !== L.object) {
2464
2464
  const c = this._getOrReturnCtx(e);
2465
- return L(c, {
2466
- code: I.invalid_type,
2467
- expected: U.object,
2465
+ return M(c, {
2466
+ code: D.invalid_type,
2467
+ expected: L.object,
2468
2468
  received: c.parsedType
2469
2469
  }), Y;
2470
2470
  }
@@ -2490,8 +2490,8 @@ class fe extends X {
2490
2490
  value: { status: "valid", value: r.data[u] }
2491
2491
  });
2492
2492
  else if (c === "strict")
2493
- a.length > 0 && (L(r, {
2494
- code: I.unrecognized_keys,
2493
+ a.length > 0 && (M(r, {
2494
+ code: D.unrecognized_keys,
2495
2495
  keys: a
2496
2496
  }), s.dirty());
2497
2497
  else if (c !== "strip") throw new Error("Internal ZodObject error: invalid unknownKeys value.");
@@ -2526,14 +2526,14 @@ class fe extends X {
2526
2526
  return this._def.shape();
2527
2527
  }
2528
2528
  strict(e) {
2529
- return z.errToObj, new fe({
2529
+ return Z.errToObj, new fe({
2530
2530
  ...this._def,
2531
2531
  unknownKeys: "strict",
2532
2532
  ...e !== void 0 ? {
2533
2533
  errorMap: (t, s) => {
2534
2534
  const r = this._def.errorMap?.(t, s).message ?? s.defaultError;
2535
2535
  return t.code === "unrecognized_keys" ? {
2536
- message: z.errToObj(e).message ?? r
2536
+ message: Z.errToObj(e).message ?? r
2537
2537
  } : {
2538
2538
  message: r
2539
2539
  };
@@ -2720,21 +2720,21 @@ fe.create = (n, e) => new fe({
2720
2720
  unknownKeys: "strip",
2721
2721
  catchall: ot.create(),
2722
2722
  typeName: G.ZodObject,
2723
- ...J(e)
2723
+ ...Q(e)
2724
2724
  });
2725
2725
  fe.strictCreate = (n, e) => new fe({
2726
2726
  shape: () => n,
2727
2727
  unknownKeys: "strict",
2728
2728
  catchall: ot.create(),
2729
2729
  typeName: G.ZodObject,
2730
- ...J(e)
2730
+ ...Q(e)
2731
2731
  });
2732
2732
  fe.lazycreate = (n, e) => new fe({
2733
2733
  shape: n,
2734
2734
  unknownKeys: "strip",
2735
2735
  catchall: ot.create(),
2736
2736
  typeName: G.ZodObject,
2737
- ...J(e)
2737
+ ...Q(e)
2738
2738
  });
2739
2739
  class In extends X {
2740
2740
  _parse(e) {
@@ -2747,8 +2747,8 @@ class In extends X {
2747
2747
  if (a.result.status === "dirty")
2748
2748
  return t.common.issues.push(...a.ctx.common.issues), a.result;
2749
2749
  const o = i.map((a) => new Be(a.ctx.common.issues));
2750
- return L(t, {
2751
- code: I.invalid_union,
2750
+ return M(t, {
2751
+ code: D.invalid_union,
2752
2752
  unionErrors: o
2753
2753
  }), Y;
2754
2754
  }
@@ -2794,8 +2794,8 @@ class In extends X {
2794
2794
  if (i)
2795
2795
  return t.common.issues.push(...i.ctx.common.issues), i.result;
2796
2796
  const a = o.map((l) => new Be(l));
2797
- return L(t, {
2798
- code: I.invalid_union,
2797
+ return M(t, {
2798
+ code: D.invalid_union,
2799
2799
  unionErrors: a
2800
2800
  }), Y;
2801
2801
  }
@@ -2807,13 +2807,13 @@ class In extends X {
2807
2807
  In.create = (n, e) => new In({
2808
2808
  options: n,
2809
2809
  typeName: G.ZodUnion,
2810
- ...J(e)
2810
+ ...Q(e)
2811
2811
  });
2812
2812
  function Os(n, e) {
2813
2813
  const t = Xe(n), s = Xe(e);
2814
2814
  if (n === e)
2815
2815
  return { valid: !0, data: n };
2816
- if (t === U.object && s === U.object) {
2816
+ if (t === L.object && s === L.object) {
2817
2817
  const r = te.objectKeys(e), i = te.objectKeys(n).filter((a) => r.indexOf(a) !== -1), o = { ...n, ...e };
2818
2818
  for (const a of i) {
2819
2819
  const l = Os(n[a], e[a]);
@@ -2822,7 +2822,7 @@ function Os(n, e) {
2822
2822
  o[a] = l.data;
2823
2823
  }
2824
2824
  return { valid: !0, data: o };
2825
- } else if (t === U.array && s === U.array) {
2825
+ } else if (t === L.array && s === L.array) {
2826
2826
  if (n.length !== e.length)
2827
2827
  return { valid: !1 };
2828
2828
  const r = [];
@@ -2833,7 +2833,7 @@ function Os(n, e) {
2833
2833
  r.push(l.data);
2834
2834
  }
2835
2835
  return { valid: !0, data: r };
2836
- } else return t === U.date && s === U.date && +n == +e ? { valid: !0, data: n } : { valid: !1 };
2836
+ } else return t === L.date && s === L.date && +n == +e ? { valid: !0, data: n } : { valid: !1 };
2837
2837
  }
2838
2838
  class Dn extends X {
2839
2839
  _parse(e) {
@@ -2841,8 +2841,8 @@ class Dn extends X {
2841
2841
  if (lr(i) || lr(o))
2842
2842
  return Y;
2843
2843
  const a = Os(i.value, o.value);
2844
- return a.valid ? ((cr(i) || cr(o)) && t.dirty(), { status: t.value, value: a.data }) : (L(s, {
2845
- code: I.invalid_intersection_types
2844
+ return a.valid ? ((cr(i) || cr(o)) && t.dirty(), { status: t.value, value: a.data }) : (M(s, {
2845
+ code: D.invalid_intersection_types
2846
2846
  }), Y);
2847
2847
  };
2848
2848
  return s.common.async ? Promise.all([
@@ -2871,27 +2871,27 @@ Dn.create = (n, e, t) => new Dn({
2871
2871
  left: n,
2872
2872
  right: e,
2873
2873
  typeName: G.ZodIntersection,
2874
- ...J(t)
2874
+ ...Q(t)
2875
2875
  });
2876
2876
  class yt extends X {
2877
2877
  _parse(e) {
2878
2878
  const { status: t, ctx: s } = this._processInputParams(e);
2879
- if (s.parsedType !== U.array)
2880
- return L(s, {
2881
- code: I.invalid_type,
2882
- expected: U.array,
2879
+ if (s.parsedType !== L.array)
2880
+ return M(s, {
2881
+ code: D.invalid_type,
2882
+ expected: L.array,
2883
2883
  received: s.parsedType
2884
2884
  }), Y;
2885
2885
  if (s.data.length < this._def.items.length)
2886
- return L(s, {
2887
- code: I.too_small,
2886
+ return M(s, {
2887
+ code: D.too_small,
2888
2888
  minimum: this._def.items.length,
2889
2889
  inclusive: !0,
2890
2890
  exact: !1,
2891
2891
  type: "array"
2892
2892
  }), Y;
2893
- !this._def.rest && s.data.length > this._def.items.length && (L(s, {
2894
- code: I.too_big,
2893
+ !this._def.rest && s.data.length > this._def.items.length && (M(s, {
2894
+ code: D.too_big,
2895
2895
  maximum: this._def.items.length,
2896
2896
  inclusive: !0,
2897
2897
  exact: !1,
@@ -2920,7 +2920,7 @@ yt.create = (n, e) => {
2920
2920
  items: n,
2921
2921
  typeName: G.ZodTuple,
2922
2922
  rest: null,
2923
- ...J(e)
2923
+ ...Q(e)
2924
2924
  });
2925
2925
  };
2926
2926
  class An extends X {
@@ -2932,10 +2932,10 @@ class An extends X {
2932
2932
  }
2933
2933
  _parse(e) {
2934
2934
  const { status: t, ctx: s } = this._processInputParams(e);
2935
- if (s.parsedType !== U.object)
2936
- return L(s, {
2937
- code: I.invalid_type,
2938
- expected: U.object,
2935
+ if (s.parsedType !== L.object)
2936
+ return M(s, {
2937
+ code: D.invalid_type,
2938
+ expected: L.object,
2939
2939
  received: s.parsedType
2940
2940
  }), Y;
2941
2941
  const r = [], i = this._def.keyType, o = this._def.valueType;
@@ -2955,12 +2955,12 @@ class An extends X {
2955
2955
  keyType: e,
2956
2956
  valueType: t,
2957
2957
  typeName: G.ZodRecord,
2958
- ...J(s)
2958
+ ...Q(s)
2959
2959
  }) : new An({
2960
2960
  keyType: qe.create(),
2961
2961
  valueType: e,
2962
2962
  typeName: G.ZodRecord,
2963
- ...J(t)
2963
+ ...Q(t)
2964
2964
  });
2965
2965
  }
2966
2966
  }
@@ -2973,10 +2973,10 @@ class pr extends X {
2973
2973
  }
2974
2974
  _parse(e) {
2975
2975
  const { status: t, ctx: s } = this._processInputParams(e);
2976
- if (s.parsedType !== U.map)
2977
- return L(s, {
2978
- code: I.invalid_type,
2979
- expected: U.map,
2976
+ if (s.parsedType !== L.map)
2977
+ return M(s, {
2978
+ code: D.invalid_type,
2979
+ expected: L.map,
2980
2980
  received: s.parsedType
2981
2981
  }), Y;
2982
2982
  const r = this._def.keyType, i = this._def.valueType, o = [...s.data.entries()].map(([a, l], c) => ({
@@ -3010,27 +3010,27 @@ pr.create = (n, e, t) => new pr({
3010
3010
  valueType: e,
3011
3011
  keyType: n,
3012
3012
  typeName: G.ZodMap,
3013
- ...J(t)
3013
+ ...Q(t)
3014
3014
  });
3015
3015
  class tn extends X {
3016
3016
  _parse(e) {
3017
3017
  const { status: t, ctx: s } = this._processInputParams(e);
3018
- if (s.parsedType !== U.set)
3019
- return L(s, {
3020
- code: I.invalid_type,
3021
- expected: U.set,
3018
+ if (s.parsedType !== L.set)
3019
+ return M(s, {
3020
+ code: D.invalid_type,
3021
+ expected: L.set,
3022
3022
  received: s.parsedType
3023
3023
  }), Y;
3024
3024
  const r = this._def;
3025
- r.minSize !== null && s.data.size < r.minSize.value && (L(s, {
3026
- code: I.too_small,
3025
+ r.minSize !== null && s.data.size < r.minSize.value && (M(s, {
3026
+ code: D.too_small,
3027
3027
  minimum: r.minSize.value,
3028
3028
  type: "set",
3029
3029
  inclusive: !0,
3030
3030
  exact: !1,
3031
3031
  message: r.minSize.message
3032
- }), t.dirty()), r.maxSize !== null && s.data.size > r.maxSize.value && (L(s, {
3033
- code: I.too_big,
3032
+ }), t.dirty()), r.maxSize !== null && s.data.size > r.maxSize.value && (M(s, {
3033
+ code: D.too_big,
3034
3034
  maximum: r.maxSize.value,
3035
3035
  type: "set",
3036
3036
  inclusive: !0,
@@ -3053,13 +3053,13 @@ class tn extends X {
3053
3053
  min(e, t) {
3054
3054
  return new tn({
3055
3055
  ...this._def,
3056
- minSize: { value: e, message: z.toString(t) }
3056
+ minSize: { value: e, message: Z.toString(t) }
3057
3057
  });
3058
3058
  }
3059
3059
  max(e, t) {
3060
3060
  return new tn({
3061
3061
  ...this._def,
3062
- maxSize: { value: e, message: z.toString(t) }
3062
+ maxSize: { value: e, message: Z.toString(t) }
3063
3063
  });
3064
3064
  }
3065
3065
  size(e, t) {
@@ -3074,7 +3074,7 @@ tn.create = (n, e) => new tn({
3074
3074
  minSize: null,
3075
3075
  maxSize: null,
3076
3076
  typeName: G.ZodSet,
3077
- ...J(e)
3077
+ ...Q(e)
3078
3078
  });
3079
3079
  class yr extends X {
3080
3080
  get schema() {
@@ -3088,15 +3088,15 @@ class yr extends X {
3088
3088
  yr.create = (n, e) => new yr({
3089
3089
  getter: n,
3090
3090
  typeName: G.ZodLazy,
3091
- ...J(e)
3091
+ ...Q(e)
3092
3092
  });
3093
3093
  class ks extends X {
3094
3094
  _parse(e) {
3095
3095
  if (e.data !== this._def.value) {
3096
3096
  const t = this._getOrReturnCtx(e);
3097
- return L(t, {
3097
+ return M(t, {
3098
3098
  received: t.data,
3099
- code: I.invalid_literal,
3099
+ code: D.invalid_literal,
3100
3100
  expected: this._def.value
3101
3101
  }), Y;
3102
3102
  }
@@ -3109,30 +3109,30 @@ class ks extends X {
3109
3109
  ks.create = (n, e) => new ks({
3110
3110
  value: n,
3111
3111
  typeName: G.ZodLiteral,
3112
- ...J(e)
3112
+ ...Q(e)
3113
3113
  });
3114
3114
  function wi(n, e) {
3115
3115
  return new Dt({
3116
3116
  values: n,
3117
3117
  typeName: G.ZodEnum,
3118
- ...J(e)
3118
+ ...Q(e)
3119
3119
  });
3120
3120
  }
3121
3121
  class Dt extends X {
3122
3122
  _parse(e) {
3123
3123
  if (typeof e.data != "string") {
3124
3124
  const t = this._getOrReturnCtx(e), s = this._def.values;
3125
- return L(t, {
3125
+ return M(t, {
3126
3126
  expected: te.joinValues(s),
3127
3127
  received: t.parsedType,
3128
- code: I.invalid_type
3128
+ code: D.invalid_type
3129
3129
  }), Y;
3130
3130
  }
3131
3131
  if (this._cache || (this._cache = new Set(this._def.values)), !this._cache.has(e.data)) {
3132
3132
  const t = this._getOrReturnCtx(e), s = this._def.values;
3133
- return L(t, {
3133
+ return M(t, {
3134
3134
  received: t.data,
3135
- code: I.invalid_enum_value,
3135
+ code: D.invalid_enum_value,
3136
3136
  options: s
3137
3137
  }), Y;
3138
3138
  }
@@ -3176,19 +3176,19 @@ Dt.create = wi;
3176
3176
  class gr extends X {
3177
3177
  _parse(e) {
3178
3178
  const t = te.getValidEnumValues(this._def.values), s = this._getOrReturnCtx(e);
3179
- if (s.parsedType !== U.string && s.parsedType !== U.number) {
3179
+ if (s.parsedType !== L.string && s.parsedType !== L.number) {
3180
3180
  const r = te.objectValues(t);
3181
- return L(s, {
3181
+ return M(s, {
3182
3182
  expected: te.joinValues(r),
3183
3183
  received: s.parsedType,
3184
- code: I.invalid_type
3184
+ code: D.invalid_type
3185
3185
  }), Y;
3186
3186
  }
3187
3187
  if (this._cache || (this._cache = new Set(te.getValidEnumValues(this._def.values))), !this._cache.has(e.data)) {
3188
3188
  const r = te.objectValues(t);
3189
- return L(s, {
3189
+ return M(s, {
3190
3190
  received: s.data,
3191
- code: I.invalid_enum_value,
3191
+ code: D.invalid_enum_value,
3192
3192
  options: r
3193
3193
  }), Y;
3194
3194
  }
@@ -3201,7 +3201,7 @@ class gr extends X {
3201
3201
  gr.create = (n, e) => new gr({
3202
3202
  values: n,
3203
3203
  typeName: G.ZodNativeEnum,
3204
- ...J(e)
3204
+ ...Q(e)
3205
3205
  });
3206
3206
  class Cn extends X {
3207
3207
  unwrap() {
@@ -3209,13 +3209,13 @@ class Cn extends X {
3209
3209
  }
3210
3210
  _parse(e) {
3211
3211
  const { ctx: t } = this._processInputParams(e);
3212
- if (t.parsedType !== U.promise && t.common.async === !1)
3213
- return L(t, {
3214
- code: I.invalid_type,
3215
- expected: U.promise,
3212
+ if (t.parsedType !== L.promise && t.common.async === !1)
3213
+ return M(t, {
3214
+ code: D.invalid_type,
3215
+ expected: L.promise,
3216
3216
  received: t.parsedType
3217
3217
  }), Y;
3218
- const s = t.parsedType === U.promise ? t.data : Promise.resolve(t.data);
3218
+ const s = t.parsedType === L.promise ? t.data : Promise.resolve(t.data);
3219
3219
  return Ae(s.then((r) => this._def.type.parseAsync(r, {
3220
3220
  path: t.path,
3221
3221
  errorMap: t.common.contextualErrorMap
@@ -3225,7 +3225,7 @@ class Cn extends X {
3225
3225
  Cn.create = (n, e) => new Cn({
3226
3226
  type: n,
3227
3227
  typeName: G.ZodPromise,
3228
- ...J(e)
3228
+ ...Q(e)
3229
3229
  });
3230
3230
  class At extends X {
3231
3231
  innerType() {
@@ -3237,7 +3237,7 @@ class At extends X {
3237
3237
  _parse(e) {
3238
3238
  const { status: t, ctx: s } = this._processInputParams(e), r = this._def.effect || null, i = {
3239
3239
  addIssue: (o) => {
3240
- L(s, o), o.fatal ? t.abort() : t.dirty();
3240
+ M(s, o), o.fatal ? t.abort() : t.dirty();
3241
3241
  },
3242
3242
  get path() {
3243
3243
  return s.path;
@@ -3311,17 +3311,17 @@ At.create = (n, e, t) => new At({
3311
3311
  schema: n,
3312
3312
  typeName: G.ZodEffects,
3313
3313
  effect: e,
3314
- ...J(t)
3314
+ ...Q(t)
3315
3315
  });
3316
3316
  At.createWithPreprocess = (n, e, t) => new At({
3317
3317
  schema: e,
3318
3318
  effect: { type: "preprocess", transform: n },
3319
3319
  typeName: G.ZodEffects,
3320
- ...J(t)
3320
+ ...Q(t)
3321
3321
  });
3322
3322
  class st extends X {
3323
3323
  _parse(e) {
3324
- return this._getType(e) === U.undefined ? Ae(void 0) : this._def.innerType._parse(e);
3324
+ return this._getType(e) === L.undefined ? Ae(void 0) : this._def.innerType._parse(e);
3325
3325
  }
3326
3326
  unwrap() {
3327
3327
  return this._def.innerType;
@@ -3330,11 +3330,11 @@ class st extends X {
3330
3330
  st.create = (n, e) => new st({
3331
3331
  innerType: n,
3332
3332
  typeName: G.ZodOptional,
3333
- ...J(e)
3333
+ ...Q(e)
3334
3334
  });
3335
3335
  class Ct extends X {
3336
3336
  _parse(e) {
3337
- return this._getType(e) === U.null ? Ae(null) : this._def.innerType._parse(e);
3337
+ return this._getType(e) === L.null ? Ae(null) : this._def.innerType._parse(e);
3338
3338
  }
3339
3339
  unwrap() {
3340
3340
  return this._def.innerType;
@@ -3343,13 +3343,13 @@ class Ct extends X {
3343
3343
  Ct.create = (n, e) => new Ct({
3344
3344
  innerType: n,
3345
3345
  typeName: G.ZodNullable,
3346
- ...J(e)
3346
+ ...Q(e)
3347
3347
  });
3348
3348
  class bs extends X {
3349
3349
  _parse(e) {
3350
3350
  const { ctx: t } = this._processInputParams(e);
3351
3351
  let s = t.data;
3352
- return t.parsedType === U.undefined && (s = this._def.defaultValue()), this._def.innerType._parse({
3352
+ return t.parsedType === L.undefined && (s = this._def.defaultValue()), this._def.innerType._parse({
3353
3353
  data: s,
3354
3354
  path: t.path,
3355
3355
  parent: t
@@ -3363,7 +3363,7 @@ bs.create = (n, e) => new bs({
3363
3363
  innerType: n,
3364
3364
  typeName: G.ZodDefault,
3365
3365
  defaultValue: typeof e.default == "function" ? e.default : () => e.default,
3366
- ...J(e)
3366
+ ...Q(e)
3367
3367
  });
3368
3368
  class Ss extends X {
3369
3369
  _parse(e) {
@@ -3406,15 +3406,15 @@ Ss.create = (n, e) => new Ss({
3406
3406
  innerType: n,
3407
3407
  typeName: G.ZodCatch,
3408
3408
  catchValue: typeof e.catch == "function" ? e.catch : () => e.catch,
3409
- ...J(e)
3409
+ ...Q(e)
3410
3410
  });
3411
3411
  class wr extends X {
3412
3412
  _parse(e) {
3413
- if (this._getType(e) !== U.nan) {
3413
+ if (this._getType(e) !== L.nan) {
3414
3414
  const s = this._getOrReturnCtx(e);
3415
- return L(s, {
3416
- code: I.invalid_type,
3417
- expected: U.nan,
3415
+ return M(s, {
3416
+ code: D.invalid_type,
3417
+ expected: L.nan,
3418
3418
  received: s.parsedType
3419
3419
  }), Y;
3420
3420
  }
@@ -3423,7 +3423,7 @@ class wr extends X {
3423
3423
  }
3424
3424
  wr.create = (n) => new wr({
3425
3425
  typeName: G.ZodNaN,
3426
- ...J(n)
3426
+ ...Q(n)
3427
3427
  });
3428
3428
  class Aa extends X {
3429
3429
  _parse(e) {
@@ -3490,7 +3490,7 @@ class Ts extends X {
3490
3490
  Ts.create = (n, e) => new Ts({
3491
3491
  innerType: n,
3492
3492
  typeName: G.ZodReadonly,
3493
- ...J(e)
3493
+ ...Q(e)
3494
3494
  });
3495
3495
  var G;
3496
3496
  (function(n) {
@@ -4135,7 +4135,7 @@ function Qa(n, e, t) {
4135
4135
  function Ka(n) {
4136
4136
  const e = [];
4137
4137
  for (let t = 1; t <= 12; t++) {
4138
- const s = V.utc(2009, t, 1);
4138
+ const s = P.utc(2009, t, 1);
4139
4139
  e.push(n(s));
4140
4140
  }
4141
4141
  return e;
@@ -4143,7 +4143,7 @@ function Ka(n) {
4143
4143
  function Xa(n) {
4144
4144
  const e = [];
4145
4145
  for (let t = 1; t <= 7; t++) {
4146
- const s = V.utc(2016, 11, 13 + t);
4146
+ const s = P.utc(2016, 11, 13 + t);
4147
4147
  e.push(n(s));
4148
4148
  }
4149
4149
  return e;
@@ -4300,7 +4300,7 @@ class se {
4300
4300
  () => {
4301
4301
  if (!this.meridiemCache) {
4302
4302
  const e = { hour: "numeric", hourCycle: "h12" };
4303
- this.meridiemCache = [V.utc(2016, 11, 13, 9), V.utc(2016, 11, 13, 19)].map(
4303
+ this.meridiemCache = [P.utc(2016, 11, 13, 9), P.utc(2016, 11, 13, 19)].map(
4304
4304
  (t) => this.extract(t, e, "dayperiod")
4305
4305
  );
4306
4306
  }
@@ -4311,7 +4311,7 @@ class se {
4311
4311
  eras(e) {
4312
4312
  return fn(this, e, ro, () => {
4313
4313
  const t = { era: e };
4314
- return this.eraCache[e] || (this.eraCache[e] = [V.utc(-40, 1, 1), V.utc(2017, 1, 1)].map(
4314
+ return this.eraCache[e] || (this.eraCache[e] = [P.utc(-40, 1, 1), P.utc(2017, 1, 1)].map(
4315
4315
  (s) => this.extract(s, t, "era")
4316
4316
  )), this.eraCache[e];
4317
4317
  });
@@ -4730,7 +4730,7 @@ class ce {
4730
4730
  * @return {void}
4731
4731
  */
4732
4732
  static resetCaches() {
4733
- se.resetCache(), He.resetCache(), V.resetCache(), al();
4733
+ se.resetCache(), He.resetCache(), P.resetCache(), al();
4734
4734
  }
4735
4735
  }
4736
4736
  class Fe {
@@ -5368,8 +5368,8 @@ class _e {
5368
5368
  const d = r(f);
5369
5369
  if (d) {
5370
5370
  const m = h.isNegativeDuration && d !== h.largestUnit ? s : 1;
5371
- let k;
5372
- return this.opts.signMode === "negativeLargestOnly" && d !== h.largestUnit ? k = "never" : this.opts.signMode === "all" ? k = "always" : k = "auto", this.num(u.get(d) * m, f.length, k);
5371
+ let b;
5372
+ return this.opts.signMode === "negativeLargestOnly" && d !== h.largestUnit ? b = "never" : this.opts.signMode === "all" ? b = "always" : b = "auto", this.num(u.get(d) * m, f.length, b);
5373
5373
  } else
5374
5374
  return f;
5375
5375
  }, o = _e.parseFormat(t), a = o.reduce(
@@ -5983,7 +5983,7 @@ class ee {
5983
5983
  format: "extended",
5984
5984
  ...e,
5985
5985
  includeOffset: !1
5986
- }, V.fromMillis(t, { zone: "UTC" }).toISOTime(e));
5986
+ }, P.fromMillis(t, { zone: "UTC" }).toISOTime(e));
5987
5987
  }
5988
5988
  /**
5989
5989
  * Returns an ISO 8601 representation of this Duration appropriate for use in JSON.
@@ -6371,13 +6371,13 @@ class le {
6371
6371
  if (s && r) {
6372
6372
  let i, o;
6373
6373
  try {
6374
- i = V.fromISO(s, t), o = i.isValid;
6374
+ i = P.fromISO(s, t), o = i.isValid;
6375
6375
  } catch {
6376
6376
  o = !1;
6377
6377
  }
6378
6378
  let a, l;
6379
6379
  try {
6380
- a = V.fromISO(r, t), l = a.isValid;
6380
+ a = P.fromISO(r, t), l = a.isValid;
6381
6381
  } catch {
6382
6382
  l = !1;
6383
6383
  }
@@ -6771,7 +6771,7 @@ class hn {
6771
6771
  * @return {boolean}
6772
6772
  */
6773
6773
  static hasDST(e = ce.defaultZone) {
6774
- const t = V.now().setZone(e).set({ month: 12 });
6774
+ const t = P.now().setZone(e).set({ month: 12 });
6775
6775
  return !e.isUniversal && t.offset !== t.set({ month: 6 }).offset;
6776
6776
  }
6777
6777
  /**
@@ -6994,7 +6994,7 @@ function _c(n) {
6994
6994
  return n.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
6995
6995
  }
6996
6996
  function Ec(n, e) {
6997
- const t = Ce(e), s = Ce(e, "{2}"), r = Ce(e, "{3}"), i = Ce(e, "{4}"), o = Ce(e, "{6}"), a = Ce(e, "{1,2}"), l = Ce(e, "{1,3}"), c = Ce(e, "{1,6}"), u = Ce(e, "{1,9}"), h = Ce(e, "{2,4}"), f = Ce(e, "{4,6}"), d = (y) => ({ regex: RegExp(_c(y.val)), deser: ([w]) => w, literal: !0 }), k = ((y) => {
6997
+ const t = Ce(e), s = Ce(e, "{2}"), r = Ce(e, "{3}"), i = Ce(e, "{4}"), o = Ce(e, "{6}"), a = Ce(e, "{1,2}"), l = Ce(e, "{1,3}"), c = Ce(e, "{1,6}"), u = Ce(e, "{1,9}"), h = Ce(e, "{2,4}"), f = Ce(e, "{4,6}"), d = (y) => ({ regex: RegExp(_c(y.val)), deser: ([_]) => _, literal: !0 }), b = ((y) => {
6998
6998
  if (n.literal)
6999
6999
  return d(y);
7000
7000
  switch (y.val) {
@@ -7117,7 +7117,7 @@ function Ec(n, e) {
7117
7117
  })(n) || {
7118
7118
  invalidReason: yc
7119
7119
  };
7120
- return k.token = n, k;
7120
+ return b.token = n, b;
7121
7121
  }
7122
7122
  const vc = {
7123
7123
  year: {
@@ -7239,7 +7239,7 @@ function Sc(n) {
7239
7239
  }
7240
7240
  let ls = null;
7241
7241
  function Tc() {
7242
- return ls || (ls = V.fromMillis(1555555555555)), ls;
7242
+ return ls || (ls = P.fromMillis(1555555555555)), ls;
7243
7243
  }
7244
7244
  function Rc(n, e) {
7245
7245
  if (n.literal)
@@ -7320,7 +7320,7 @@ function dt(n, e) {
7320
7320
  loc: n.loc,
7321
7321
  invalid: n.invalid
7322
7322
  };
7323
- return new V({ ...t, ...e, old: t });
7323
+ return new P({ ...t, ...e, old: t });
7324
7324
  }
7325
7325
  function Eo(n, e, t) {
7326
7326
  let s = n - e * 60 * 1e3;
@@ -7370,14 +7370,14 @@ function zr(n, e) {
7370
7370
  function kt(n, e, t, s, r, i) {
7371
7371
  const { setZone: o, zone: a } = t;
7372
7372
  if (n && Object.keys(n).length !== 0 || e) {
7373
- const l = e || a, c = V.fromObject(n, {
7373
+ const l = e || a, c = P.fromObject(n, {
7374
7374
  ...t,
7375
7375
  zone: l,
7376
7376
  specificOffset: i
7377
7377
  });
7378
7378
  return o ? c : c.setZone(a);
7379
7379
  } else
7380
- return V.invalid(
7380
+ return P.invalid(
7381
7381
  new Fe("unparsable", `the input "${r}" can't be parsed as ${s}`)
7382
7382
  );
7383
7383
  }
@@ -7502,7 +7502,7 @@ function Cc(n) {
7502
7502
  function Hr(n, e) {
7503
7503
  const t = tt(e.zone, ce.defaultZone);
7504
7504
  if (!t.isValid)
7505
- return V.invalid(Gt(t));
7505
+ return P.invalid(Gt(t));
7506
7506
  const s = se.fromObject(e);
7507
7507
  let r, i;
7508
7508
  if (H(n.year))
@@ -7512,11 +7512,11 @@ function Hr(n, e) {
7512
7512
  H(n[l]) && (n[l] = vo[l]);
7513
7513
  const o = Bi(n) || Hi(n);
7514
7514
  if (o)
7515
- return V.invalid(o);
7515
+ return P.invalid(o);
7516
7516
  const a = Cc(t);
7517
7517
  [r, i] = _n(n, a, t);
7518
7518
  }
7519
- return new V({ ts: r, zone: t, loc: s, o: i });
7519
+ return new P({ ts: r, zone: t, loc: s, o: i });
7520
7520
  }
7521
7521
  function Gr(n, e, t) {
7522
7522
  const s = H(t.round) ? !0 : t.round, r = H(t.rounding) ? "trunc" : t.rounding, i = (a, l) => (a = Hs(a, s || t.calendary ? 0 : 2, t.calendary ? "round" : r), e.loc.clone(t).relFormatter(t).format(a, l)), o = (a) => t.calendary ? e.hasSame(n, a) ? 0 : e.startOf(a).diff(n.startOf(a), a).get(a) : e.diff(n, a).get(a);
@@ -7535,7 +7535,7 @@ function Yr(n) {
7535
7535
  }
7536
7536
  let Yt;
7537
7537
  const Ps = /* @__PURE__ */ new Map();
7538
- class V {
7538
+ class P {
7539
7539
  /**
7540
7540
  * @access private
7541
7541
  */
@@ -7562,7 +7562,7 @@ class V {
7562
7562
  * @return {DateTime}
7563
7563
  */
7564
7564
  static now() {
7565
- return new V({});
7565
+ return new P({});
7566
7566
  }
7567
7567
  /**
7568
7568
  * Create a local DateTime
@@ -7628,13 +7628,13 @@ class V {
7628
7628
  static fromJSDate(e, t = {}) {
7629
7629
  const s = dl(e) ? e.valueOf() : NaN;
7630
7630
  if (Number.isNaN(s))
7631
- return V.invalid("invalid input");
7631
+ return P.invalid("invalid input");
7632
7632
  const r = tt(t.zone, ce.defaultZone);
7633
- return r.isValid ? new V({
7633
+ return r.isValid ? new P({
7634
7634
  ts: s,
7635
7635
  zone: r,
7636
7636
  loc: se.fromObject(t)
7637
- }) : V.invalid(Gt(r));
7637
+ }) : P.invalid(Gt(r));
7638
7638
  }
7639
7639
  /**
7640
7640
  * Create a DateTime from a number of milliseconds since the epoch (meaning since 1 January 1970 00:00:00 UTC). Uses the default zone.
@@ -7649,7 +7649,7 @@ class V {
7649
7649
  */
7650
7650
  static fromMillis(e, t = {}) {
7651
7651
  if (rt(e))
7652
- return e < -Zr || e > Zr ? V.invalid("Timestamp out of range") : new V({
7652
+ return e < -Zr || e > Zr ? P.invalid("Timestamp out of range") : new P({
7653
7653
  ts: e,
7654
7654
  zone: tt(t.zone, ce.defaultZone),
7655
7655
  loc: se.fromObject(t)
@@ -7671,7 +7671,7 @@ class V {
7671
7671
  */
7672
7672
  static fromSeconds(e, t = {}) {
7673
7673
  if (rt(e))
7674
- return new V({
7674
+ return new P({
7675
7675
  ts: e * 1e3,
7676
7676
  zone: tt(t.zone, ce.defaultZone),
7677
7677
  loc: se.fromObject(t)
@@ -7715,7 +7715,7 @@ class V {
7715
7715
  e = e || {};
7716
7716
  const s = tt(t.zone, ce.defaultZone);
7717
7717
  if (!s.isValid)
7718
- return V.invalid(Gt(s));
7718
+ return P.invalid(Gt(s));
7719
7719
  const r = se.fromObject(t), i = Vn(e, Br), { minDaysInFirstWeek: o, startOfWeek: a } = Ar(i, r), l = ce.now(), c = H(t.specificOffset) ? s.offset(l) : t.specificOffset, u = !H(i.ordinal), h = !H(i.year), f = !H(i.month) || !H(i.day), d = h || f, m = i.weekYear || i.weekNumber;
7720
7720
  if ((d || u) && m)
7721
7721
  throw new St(
@@ -7723,27 +7723,27 @@ class V {
7723
7723
  );
7724
7724
  if (f && u)
7725
7725
  throw new St("Can't mix ordinal dates with month/day");
7726
- const k = m || i.weekday && !d;
7727
- let y, w, b = pn(l, c);
7728
- k ? (y = Dc, w = xc, b = Pn(b, o, a)) : u ? (y = Ac, w = Ic, b = as(b)) : (y = En, w = vo);
7729
- let N = !1;
7726
+ const b = m || i.weekday && !d;
7727
+ let y, _, S = pn(l, c);
7728
+ b ? (y = Dc, _ = xc, S = Pn(S, o, a)) : u ? (y = Ac, _ = Ic, S = as(S)) : (y = En, _ = vo);
7729
+ let x = !1;
7730
7730
  for (const g of y) {
7731
- const O = i[g];
7732
- H(O) ? N ? i[g] = w[g] : i[g] = b[g] : N = !0;
7731
+ const k = i[g];
7732
+ H(k) ? x ? i[g] = _[g] : i[g] = S[g] : x = !0;
7733
7733
  }
7734
- const p = k ? ll(i, o, a) : u ? cl(i) : Bi(i), T = p || Hi(i);
7735
- if (T)
7736
- return V.invalid(T);
7737
- const C = k ? Ir(i, o, a) : u ? Dr(i) : i, [v, Z] = _n(C, c, s), x = new V({
7734
+ const p = b ? ll(i, o, a) : u ? cl(i) : Bi(i), R = p || Hi(i);
7735
+ if (R)
7736
+ return P.invalid(R);
7737
+ const A = b ? Ir(i, o, a) : u ? Dr(i) : i, [v, j] = _n(A, c, s), I = new P({
7738
7738
  ts: v,
7739
7739
  zone: s,
7740
- o: Z,
7740
+ o: j,
7741
7741
  loc: r
7742
7742
  });
7743
- return i.weekday && d && e.weekday !== x.weekday ? V.invalid(
7743
+ return i.weekday && d && e.weekday !== I.weekday ? P.invalid(
7744
7744
  "mismatched weekday",
7745
- `you can't specify both a weekday of ${i.weekday} and a date of ${x.toISO()}`
7746
- ) : x.isValid ? x : V.invalid(x.invalid);
7745
+ `you can't specify both a weekday of ${i.weekday} and a date of ${I.toISO()}`
7746
+ ) : I.isValid ? I : P.invalid(I.invalid);
7747
7747
  }
7748
7748
  /**
7749
7749
  * Create a DateTime from an ISO 8601 string
@@ -7827,13 +7827,13 @@ class V {
7827
7827
  numberingSystem: i,
7828
7828
  defaultToEN: !0
7829
7829
  }), [a, l, c, u] = Nc(o, e, t);
7830
- return u ? V.invalid(u) : kt(a, l, s, `format ${t}`, e, c);
7830
+ return u ? P.invalid(u) : kt(a, l, s, `format ${t}`, e, c);
7831
7831
  }
7832
7832
  /**
7833
7833
  * @deprecated use fromFormat instead
7834
7834
  */
7835
7835
  static fromString(e, t, s = {}) {
7836
- return V.fromFormat(e, t, s);
7836
+ return P.fromFormat(e, t, s);
7837
7837
  }
7838
7838
  /**
7839
7839
  * Create a DateTime from a SQL date, time, or datetime
@@ -7872,7 +7872,7 @@ class V {
7872
7872
  const s = e instanceof Fe ? e : new Fe(e, t);
7873
7873
  if (ce.throwOnInvalid)
7874
7874
  throw new Fa(s);
7875
- return new V({ invalid: s });
7875
+ return new P({ invalid: s });
7876
7876
  }
7877
7877
  /**
7878
7878
  * Check if an object is an instance of DateTime. Works across context boundaries
@@ -8311,7 +8311,7 @@ class V {
8311
8311
  }
8312
8312
  return dt(this, { ts: r, zone: e });
8313
8313
  } else
8314
- return V.invalid(Gt(e));
8314
+ return P.invalid(Gt(e));
8315
8315
  }
8316
8316
  /**
8317
8317
  * "Set" the locale, numberingSystem, or outputCalendar. Returns a newly-constructed DateTime.
@@ -8772,7 +8772,7 @@ class V {
8772
8772
  * @return {Duration}
8773
8773
  */
8774
8774
  diffNow(e = "milliseconds", t = {}) {
8775
- return this.diff(V.now(), e, t);
8775
+ return this.diff(P.now(), e, t);
8776
8776
  }
8777
8777
  /**
8778
8778
  * Return an Interval spanning between this DateTime and another DateTime
@@ -8829,7 +8829,7 @@ class V {
8829
8829
  */
8830
8830
  toRelative(e = {}) {
8831
8831
  if (!this.isValid) return null;
8832
- const t = e.base || V.fromObject({}, { zone: this.zone }), s = e.padding ? this < t ? -e.padding : e.padding : 0;
8832
+ const t = e.base || P.fromObject({}, { zone: this.zone }), s = e.padding ? this < t ? -e.padding : e.padding : 0;
8833
8833
  let r = ["years", "months", "days", "hours", "minutes", "seconds"], i = e.unit;
8834
8834
  return Array.isArray(e.unit) && (r = e.unit, i = void 0), Gr(t, this.plus(s), {
8835
8835
  ...e,
@@ -8852,7 +8852,7 @@ class V {
8852
8852
  * @example DateTime.now().minus({ days: 2 }).toRelativeCalendar() //=> "2 days ago"
8853
8853
  */
8854
8854
  toRelativeCalendar(e = {}) {
8855
- return this.isValid ? Gr(e.base || V.fromObject({}, { zone: this.zone }), this, {
8855
+ return this.isValid ? Gr(e.base || P.fromObject({}, { zone: this.zone }), this, {
8856
8856
  ...e,
8857
8857
  numeric: "auto",
8858
8858
  units: ["years", "months", "days"],
@@ -8865,7 +8865,7 @@ class V {
8865
8865
  * @return {DateTime} the min DateTime, or undefined if called with no argument
8866
8866
  */
8867
8867
  static min(...e) {
8868
- if (!e.every(V.isDateTime))
8868
+ if (!e.every(P.isDateTime))
8869
8869
  throw new we("min requires all arguments be DateTimes");
8870
8870
  return Cr(e, (t) => t.valueOf(), Math.min);
8871
8871
  }
@@ -8875,7 +8875,7 @@ class V {
8875
8875
  * @return {DateTime} the max DateTime, or undefined if called with no argument
8876
8876
  */
8877
8877
  static max(...e) {
8878
- if (!e.every(V.isDateTime))
8878
+ if (!e.every(P.isDateTime))
8879
8879
  throw new we("max requires all arguments be DateTimes");
8880
8880
  return Cr(e, (t) => t.valueOf(), Math.max);
8881
8881
  }
@@ -8899,7 +8899,7 @@ class V {
8899
8899
  * @deprecated use fromFormatExplain instead
8900
8900
  */
8901
8901
  static fromStringExplain(e, t, s = {}) {
8902
- return V.fromFormatExplain(e, t, s);
8902
+ return P.fromFormatExplain(e, t, s);
8903
8903
  }
8904
8904
  /**
8905
8905
  * Build a parser for `fmt` using the given locale. This parser can be passed
@@ -8946,7 +8946,7 @@ class V {
8946
8946
  `fromFormatParser called with a locale of ${o}, but the format parser was created for ${t.locale}`
8947
8947
  );
8948
8948
  const { result: a, zone: l, specificOffset: c, invalidReason: u } = t.explainFromTokens(e);
8949
- return u ? V.invalid(u) : kt(
8949
+ return u ? P.invalid(u) : kt(
8950
8950
  a,
8951
8951
  l,
8952
8952
  s,
@@ -9112,12 +9112,12 @@ class V {
9112
9112
  }
9113
9113
  }
9114
9114
  function zt(n) {
9115
- if (V.isDateTime(n))
9115
+ if (P.isDateTime(n))
9116
9116
  return n;
9117
9117
  if (n && n.valueOf && rt(n.valueOf()))
9118
- return V.fromJSDate(n);
9118
+ return P.fromJSDate(n);
9119
9119
  if (n && typeof n == "object")
9120
- return V.fromObject(n);
9120
+ return P.fromObject(n);
9121
9121
  throw new we(
9122
9122
  `Unknown datetime argument: ${n}, of type ${typeof n}`
9123
9123
  );
@@ -9186,10 +9186,10 @@ const $c = (n, e) => {
9186
9186
  t ? (s = We({
9187
9187
  seconds: ht(),
9188
9188
  nanoseconds: ht()
9189
- }), n.min && n.max ? s = s.describe(`${r}Must be between ${V.fromMillis(n.min).toLocaleString(V.DATE_MED)} and ${V.fromMillis(n.max).toLocaleString(V.DATE_MED)}`) : n.min ? s = s.describe(`${r}Must be greater than or equal to ${V.fromMillis(n.min).toLocaleString(V.DATE_MED)}`) : n.max ? s = s.describe(`${r}Must be less than or equal to ${V.fromMillis(n.max).toLocaleString(V.DATE_MED)}`) : r && (s = s.describe(r.trim()))) : (s = Fc(), n.min && (s = s.refine((l) => l.toMillis() >= n.min, {
9190
- message: `Must be greater than or equal to ${V.fromMillis(n.min).toLocaleString(V.DATE_MED)}`
9189
+ }), n.min && n.max ? s = s.describe(`${r}Must be between ${P.fromMillis(n.min).toLocaleString(P.DATE_MED)} and ${P.fromMillis(n.max).toLocaleString(P.DATE_MED)}`) : n.min ? s = s.describe(`${r}Must be greater than or equal to ${P.fromMillis(n.min).toLocaleString(P.DATE_MED)}`) : n.max ? s = s.describe(`${r}Must be less than or equal to ${P.fromMillis(n.max).toLocaleString(P.DATE_MED)}`) : r && (s = s.describe(r.trim()))) : (s = Fc(), n.min && (s = s.refine((l) => l.toMillis() >= n.min, {
9190
+ message: `Must be greater than or equal to ${P.fromMillis(n.min).toLocaleString(P.DATE_MED)}`
9191
9191
  })), n.max && (s = s.refine((l) => l.toMillis() <= n.max, {
9192
- message: `Must be less than or equal to ${V.fromMillis(n.max).toLocaleString(V.DATE_MED)}`
9192
+ message: `Must be less than or equal to ${P.fromMillis(n.max).toLocaleString(P.DATE_MED)}`
9193
9193
  })));
9194
9194
  break;
9195
9195
  case "Array":
@@ -9224,7 +9224,7 @@ const $c = (n, e) => {
9224
9224
  a[`attribute-${c.labels.collection}-${u.type}`] = Kt().optional();
9225
9225
  }), c.access.entityRestrictions?.restrictions?.forEach((u) => {
9226
9226
  if (u.type === "Individual" && (a[`accessible-${c.labels.collection}-${c.labels.collection}`] = We({}).catchall(ge()).optional()), u.type === "Parent" || u.type === "Parent_Property") {
9227
- const h = W(c.fields, u.collectionField);
9227
+ const h = V(c.fields, u.collectionField);
9228
9228
  a[`accessible-${c.labels.collection}-${h.collection}`] = We({}).catchall(ge()).optional();
9229
9229
  }
9230
9230
  });
@@ -9242,143 +9242,143 @@ const $c = (n, e) => {
9242
9242
  for (const a of s.fields)
9243
9243
  await Jr(a.custom?.preValidate, r);
9244
9244
  return Ma(n, t, i).parse(e), e;
9245
- }, Qs = (n, e, t, s, r, i, o, a, l, c, u, h, f, d, m, k, y, w, b, N, p) => {
9246
- const { fields: T } = o;
9247
- T.filter((g) => "unique" in g && g.unique).forEach((g) => {
9245
+ }, Qs = (n, e, t, s, r, i, o, a, l, c, u, h, f, d, m, b, y, _, S, x, p) => {
9246
+ const { fields: R } = o;
9247
+ R.filter((g) => "unique" in g && g.unique).forEach((g) => {
9248
9248
  n !== "delete" && (typeof r[g.name] == "string" || typeof r[g.name] == "number") && (e.set(d(g, r[g.name].toString().toLowerCase().replace(/\s/g, "---").replaceAll("/", "|||")), {
9249
9249
  id: s,
9250
9250
  Collection_Path: t
9251
9251
  }), p && p.size++);
9252
- }), T.forEach((g) => {
9252
+ }), R.forEach((g) => {
9253
9253
  if (ct(g, o, i)) {
9254
- const O = dn(g, o, i), _ = {};
9255
- r[g.name] !== void 0 && (_[g.name] = r[g.name], K(g) && (_[`${g.name}_Array`] = r[`${g.name}_Array`])), O.forEach((A) => {
9256
- r[A.name] !== void 0 && (K(A) ? _[`${A.name}_Array`] = r[`${A.name}_Array`] : _[A.name] = r[A.name]);
9257
- }), Object.keys(_).length > 0 && (n === "create" && (_.Collection_Path = t, _.Collection_Path_String = t.join("/"), e.set(f(g), _)), n === "update" && e.update(f(g), _), n === "delete" && e.delete(f(g)), p && p.size++);
9254
+ const k = dn(g, o, i), E = {};
9255
+ r[g.name] !== void 0 && (E[g.name] = r[g.name], K(g) && (E[`${g.name}_Array`] = r[`${g.name}_Array`])), k.forEach((B) => {
9256
+ r[B.name] !== void 0 && (K(B) ? E[`${B.name}_Array`] = r[`${B.name}_Array`] : E[B.name] = r[B.name]);
9257
+ }), Object.keys(E).length > 0 && (n === "create" && (E.Collection_Path = t, E.Collection_Path_String = t.join("/"), e.set(f(g), E)), n === "update" && e.update(f(g), E), n === "delete" && e.delete(f(g)), p && p.size++);
9258
9258
  }
9259
9259
  });
9260
- const C = l[o.labels.collection];
9261
- for (const g of C) {
9262
- const O = ia(g, o), _ = { ...r };
9263
- O.forEach((A) => {
9264
- delete _[A.name], delete _[`${A.name}_Array`], delete _[`${A.name}_Single`], delete _[`${A.name}_Lowercase`];
9265
- }), Object.keys(_).length > 0 && (n === "create" && (_.Collection_Path ||= t, _.Collection_Path_String = t.join("/"), e.set(m(g.key), _)), n === "update" && e.update(m(g.key), _), n === "delete" && e.delete(m(g.key)), p && p.size++);
9266
- }
9267
- const v = (g, O) => {
9268
- let _ = 1;
9269
- ct(O, g, i) && _++, g.fields.forEach((E) => {
9270
- ct(E, g, i) && JSON.parse(es(dn(E, g, i))).includes(O.name) && _++;
9260
+ const A = l[o.labels.collection];
9261
+ for (const g of A) {
9262
+ const k = ia(g, o), E = { ...r };
9263
+ k.forEach((B) => {
9264
+ delete E[B.name], delete E[`${B.name}_Array`], delete E[`${B.name}_Single`], delete E[`${B.name}_Lowercase`];
9265
+ }), Object.keys(E).length > 0 && (n === "create" && (E.Collection_Path ||= t, E.Collection_Path_String = t.join("/"), e.set(m(g.key), E)), n === "update" && e.update(m(g.key), E), n === "delete" && e.delete(m(g.key)), p && p.size++);
9266
+ }
9267
+ const v = (g, k) => {
9268
+ let E = 1;
9269
+ ct(k, g, i) && E++, g.fields.forEach((w) => {
9270
+ ct(w, g, i) && JSON.parse(es(dn(w, g, i))).includes(k.name) && E++;
9271
9271
  });
9272
- const A = l[g.labels.collection];
9273
- for (const E of A)
9274
- E.fields.some((D) => D.name === O.name) && K(O) && _++;
9275
- return _;
9276
- }, Z = (g, O, _, A, E) => {
9277
- const D = {};
9278
- D[`${_.name}.${s}`] = h(), D[`${_.name}_Array`] = u(s), D[`${_.name}_Single`] = h(), e.update(k(E, A), D), ct(_, O, i) && e.update(y(g, _.name, A), {
9279
- [`${_.name}.${s}`]: h(),
9280
- [`${_.name}_Array`]: u(s)
9281
- }), O.fields.forEach((F) => {
9282
- ct(F, O, i) && JSON.parse(es(dn(F, O, i))).includes(_.name) && e.update(y(g, F.name, A), {
9283
- [`${_.name}_Array`]: u(s)
9272
+ const B = l[g.labels.collection];
9273
+ for (const w of B)
9274
+ w.fields.some((N) => N.name === k.name) && K(k) && E++;
9275
+ return E;
9276
+ }, j = (g, k, E, B, w) => {
9277
+ const N = {};
9278
+ N[`${E.name}.${s}`] = h(), N[`${E.name}_Array`] = u(s), N[`${E.name}_Single`] = h(), e.update(b(w, B), N), ct(E, k, i) && e.update(y(g, E.name, B), {
9279
+ [`${E.name}.${s}`]: h(),
9280
+ [`${E.name}_Array`]: u(s)
9281
+ }), k.fields.forEach((C) => {
9282
+ ct(C, k, i) && JSON.parse(es(dn(C, k, i))).includes(E.name) && e.update(y(g, C.name, B), {
9283
+ [`${E.name}_Array`]: u(s)
9284
9284
  });
9285
9285
  });
9286
- const R = l[O.labels.collection];
9287
- for (const F of R)
9288
- F.fields.some((M) => M.name === _.name) && K(_) && e.update(w(g, F.key, A), D);
9286
+ const T = l[k.labels.collection];
9287
+ for (const C of T)
9288
+ C.fields.some((F) => F.name === E.name) && K(E) && e.update(_(g, C.key, B), N);
9289
9289
  };
9290
9290
  if (n === "delete")
9291
9291
  return;
9292
- const x = T.filter((g) => K(g) && g.twoWay);
9292
+ const I = R.filter((g) => K(g) && g.twoWay);
9293
9293
  if (!a?.noTwoWay) {
9294
- for (const g of x) {
9294
+ for (const g of I) {
9295
9295
  if (!p)
9296
9296
  throw new Error("VALIDATION_ERROR: batchSize is required");
9297
- const O = i.collections[g.collection], _ = W(O.fields, g.twoWay), A = ft(O, O.fields), E = Array.from(A).map((D) => D.name);
9298
- if (!_)
9297
+ const k = i.collections[g.collection], E = V(k.fields, g.twoWay), B = ft(k, k.fields), w = Array.from(B).map((N) => N.name);
9298
+ if (!E)
9299
9299
  throw new Error(`SCHEMA_ERROR: Field ${g.twoWay} not found in collection ${g.collection}`);
9300
- if (K(_)) {
9300
+ if (K(E)) {
9301
9301
  if (r[`${g.name}_Array`])
9302
- for (const [D, R] of Object.entries(r[g.name])) {
9303
- if (n === "update" && b && b[`${g.name}_Array`]?.includes(D))
9302
+ for (const [N, T] of Object.entries(r[g.name])) {
9303
+ if (n === "update" && S && S[`${g.name}_Array`]?.includes(N))
9304
9304
  continue;
9305
- const F = { ...b, ...r };
9306
- nt(F);
9307
- const M = {};
9308
- _.includeFields && _.includeFields.forEach((S) => {
9309
- if (F[S] !== void 0) {
9310
- M[S] = F[S];
9311
- const q = W(o.fields, S);
9312
- wt(o, [q]).size === 1 && (M[`${S}_Lowercase`] = F[`${S}_Lowercase`]);
9305
+ const C = { ...S, ...r };
9306
+ nt(C);
9307
+ const F = {};
9308
+ E.includeFields && E.includeFields.forEach((O) => {
9309
+ if (C[O] !== void 0) {
9310
+ F[O] = C[O];
9311
+ const z = V(o.fields, O);
9312
+ wt(o, [z]).size === 1 && (F[`${O}_Lowercase`] = C[`${O}_Lowercase`]);
9313
9313
  }
9314
9314
  });
9315
- const P = {
9315
+ const W = {
9316
9316
  [`${g.twoWay}.${s}`]: {
9317
9317
  Collection_Path: t,
9318
- ...M
9318
+ ...F
9319
9319
  },
9320
9320
  [`${g.twoWay}_Array`]: c(s)
9321
9321
  };
9322
- E.includes(_.name) && (P[`${g.twoWay}_Single`] = {
9322
+ w.includes(E.name) && (W[`${g.twoWay}_Single`] = {
9323
9323
  Collection_Path: t,
9324
- ...M
9324
+ ...F
9325
9325
  });
9326
- const j = Sn(r);
9327
- e.update(k(R.Collection_Path, D), {
9328
- ...P,
9329
- ...j
9330
- }), p.size++, ct(_, O, i) && (e.update(y(g, _.name, D), {
9331
- [`${_.name}.${s}`]: {
9326
+ const U = Sn(r);
9327
+ e.update(b(T.Collection_Path, N), {
9328
+ ...W,
9329
+ ...U
9330
+ }), p.size++, ct(E, k, i) && (e.update(y(g, E.name, N), {
9331
+ [`${E.name}.${s}`]: {
9332
9332
  Collection_Path: t,
9333
- ...M
9333
+ ...F
9334
9334
  },
9335
- [`${_.name}_Array`]: c(s)
9336
- }), p.size++), O.fields.forEach((S) => {
9337
- if (ct(S, O, i)) {
9338
- const q = JSON.parse(es(dn(S, O, i))), B = {};
9339
- q.includes(_.name) && (B[`${g.twoWay}_Array`] = c(s)), Object.keys(j).forEach((re) => {
9340
- q.includes(re) && (B[re] = j[re]);
9341
- }), Object.keys(B).length > 0 && (e.update(y(g, S.name, D), B), p.size++);
9335
+ [`${E.name}_Array`]: c(s)
9336
+ }), p.size++), k.fields.forEach((O) => {
9337
+ if (ct(O, k, i)) {
9338
+ const z = JSON.parse(es(dn(O, k, i))), q = {};
9339
+ z.includes(E.name) && (q[`${g.twoWay}_Array`] = c(s)), Object.keys(U).forEach((re) => {
9340
+ z.includes(re) && (q[re] = U[re]);
9341
+ }), Object.keys(q).length > 0 && (e.update(y(g, O.name, N), q), p.size++);
9342
9342
  }
9343
9343
  });
9344
- const Q = l[O.labels.collection];
9345
- for (const S of Q)
9346
- if (S.fields.some((q) => q.name === _.name)) {
9347
- const q = { ...P };
9348
- Object.keys(j).forEach((B) => {
9349
- S.fields.some((re) => re.name === B) && (q[B] = j[B]);
9350
- }), Object.keys(q).length > 0 && (e.update(w(g, S.key, D), q), p.size++);
9344
+ const J = l[k.labels.collection];
9345
+ for (const O of J)
9346
+ if (O.fields.some((z) => z.name === E.name)) {
9347
+ const z = { ...W };
9348
+ Object.keys(U).forEach((q) => {
9349
+ O.fields.some((re) => re.name === q) && (z[q] = U[q]);
9350
+ }), Object.keys(z).length > 0 && (e.update(_(g, O.key, N), z), p.size++);
9351
9351
  }
9352
9352
  }
9353
9353
  } else
9354
- throw new Error(`SCHEMA_ERROR: Invalid field type: ${_.type}`);
9354
+ throw new Error(`SCHEMA_ERROR: Invalid field type: ${E.type}`);
9355
9355
  }
9356
9356
  p && p.size > 500 && console.error(new Error(`VALIDATION_ERROR: ${p.size} operations in the Firestore transaction has exceeded the recommended limit of 500. This is likely due to a large number of two way updates, roles, dependencies on the collection, unique field checks, entity restrictions (in permissions when dealing with user collections) or relation hierarchy checks.`));
9357
- for (const g of x) {
9357
+ for (const g of I) {
9358
9358
  if (!p)
9359
9359
  throw new Error("VALIDATION_ERROR: batchSize is required");
9360
- const O = i.collections[g.collection], _ = W(O.fields, g.twoWay);
9361
- if (!_)
9360
+ const k = i.collections[g.collection], E = V(k.fields, g.twoWay);
9361
+ if (!E)
9362
9362
  throw new Error(`SCHEMA_ERROR: Field ${g.twoWay} not found in collection ${g.collection}`);
9363
- if (K(_)) {
9364
- if (n === "update" && b && !(r[g.name] && Me(r[g.name])) && r[`${g.name}_Array`] && b[`${g.name}_Array`]?.length > 0)
9365
- for (const [A, E] of Object.entries(b[g.name]))
9366
- !r[`${g.name}_Array`].includes(A) && !N?.get(g.name)?.includes(A) && (p.size += v(O, _), p.size <= 500 && Z(g, O, _, A, E.Collection_Path));
9363
+ if (K(E)) {
9364
+ if (n === "update" && S && !(r[g.name] && Me(r[g.name])) && r[`${g.name}_Array`] && S[`${g.name}_Array`]?.length > 0)
9365
+ for (const [B, w] of Object.entries(S[g.name]))
9366
+ !r[`${g.name}_Array`].includes(B) && !x?.get(g.name)?.includes(B) && (p.size += v(k, E), p.size <= 500 && j(g, k, E, B, w.Collection_Path));
9367
9367
  } else
9368
- throw new Error(`SCHEMA_ERROR: Invalid field type: ${_.type}`);
9368
+ throw new Error(`SCHEMA_ERROR: Invalid field type: ${E.type}`);
9369
9369
  }
9370
- for (const g of x) {
9370
+ for (const g of I) {
9371
9371
  if (!p)
9372
9372
  throw new Error("VALIDATION_ERROR: batchSize is required");
9373
- const O = i.collections[g.collection], _ = W(O.fields, g.twoWay);
9374
- if (!_)
9373
+ const k = i.collections[g.collection], E = V(k.fields, g.twoWay);
9374
+ if (!E)
9375
9375
  throw new Error(`SCHEMA_ERROR: Field ${g.twoWay} not found in collection ${g.collection}`);
9376
- if (K(_)) {
9377
- if (n === "update" && b && r[g.name] && Me(r[g.name]) && b[`${g.name}_Array`]?.length > 0)
9378
- for (const [A, E] of Object.entries(b[g.name]))
9379
- N?.get(g.name)?.includes(A) || (p.size += v(O, _), p.size <= 500 && Z(g, O, _, A, E.Collection_Path));
9376
+ if (K(E)) {
9377
+ if (n === "update" && S && r[g.name] && Me(r[g.name]) && S[`${g.name}_Array`]?.length > 0)
9378
+ for (const [B, w] of Object.entries(S[g.name]))
9379
+ x?.get(g.name)?.includes(B) || (p.size += v(k, E), p.size <= 500 && j(g, k, E, B, w.Collection_Path));
9380
9380
  } else
9381
- throw new Error(`SCHEMA_ERROR: Invalid field type: ${_.type}`);
9381
+ throw new Error(`SCHEMA_ERROR: Invalid field type: ${E.type}`);
9382
9382
  }
9383
9383
  }
9384
9384
  }, Ve = (n) => {
@@ -9568,209 +9568,209 @@ const Tt = {
9568
9568
  const d = r.collections?.[l.collection];
9569
9569
  if (!r.Role)
9570
9570
  throw new Error("PERMISSION_DENIED");
9571
- const m = d && Te("Read", d), k = ui(a, t, r), y = li(a, r), w = Ls(a, r), b = ci(a, t, r), N = (E = []) => {
9572
- const D = [], R = pi(r.Role, a, t);
9573
- if (!R)
9571
+ const m = d && Te("Read", d), b = ui(a, t, r), y = li(a, r), _ = Ls(a, r), S = ci(a, t, r), x = (w = []) => {
9572
+ const N = [], T = pi(r.Role, a, t);
9573
+ if (!T)
9574
9574
  throw new Error("PERMISSION_DENIED");
9575
9575
  if (m) {
9576
- let F = i.collection("tenants").doc(n).collection("system_fields").doc(l.collection).collection(`${l.collection}-${R.key}`).where("Collection_Path_String", "==", e.join("/"));
9577
- E.forEach((M) => {
9578
- F = F.where(...M);
9579
- }), D.push(F);
9580
- } else if (k)
9581
- for (const F of k) {
9582
- let M = i.collection("tenants").doc(n).collection("system_fields").doc(l.collection).collection(`${l.collection}-${F.field}`).where("Collection_Path_String", "==", e.join("/"));
9583
- E.forEach((P) => {
9584
- M = M.where(...P);
9585
- }), D.push(M);
9576
+ let C = i.collection("tenants").doc(n).collection("system_fields").doc(l.collection).collection(`${l.collection}-${T.key}`).where("Collection_Path_String", "==", e.join("/"));
9577
+ w.forEach((F) => {
9578
+ C = C.where(...F);
9579
+ }), N.push(C);
9580
+ } else if (b)
9581
+ for (const C of b) {
9582
+ let F = i.collection("tenants").doc(n).collection("system_fields").doc(l.collection).collection(`${l.collection}-${C.field}`).where("Collection_Path_String", "==", e.join("/"));
9583
+ w.forEach((W) => {
9584
+ F = F.where(...W);
9585
+ }), N.push(F);
9586
9586
  }
9587
- return D;
9588
- }, p = y.filter((E) => "operations" in E && E.operations ? E.operations.includes("Read") : !0);
9589
- if (p.length === 0 && w.length === 0 && b.length === 0)
9590
- return N();
9591
- let T = 0;
9592
- const C = (E) => {
9593
- E && (T === 0 ? T = E : T *= E);
9587
+ return N;
9588
+ }, p = y.filter((w) => "operations" in w && w.operations ? w.operations.includes("Read") : !0);
9589
+ if (p.length === 0 && _.length === 0 && S.length === 0)
9590
+ return x();
9591
+ let R = 0;
9592
+ const A = (w) => {
9593
+ w && (R === 0 ? R = w : R *= w);
9594
9594
  };
9595
9595
  if (p.length > 0) {
9596
- for (const E of p)
9597
- if (E.operations && E.type === "Record_Property") {
9598
- const D = E.roles.find((R) => R.role === r.Role);
9599
- if (!D)
9596
+ for (const w of p)
9597
+ if (w.operations && w.type === "Record_Property") {
9598
+ const N = w.roles.find((T) => T.role === r.Role);
9599
+ if (!N)
9600
9600
  throw new Error("PERMISSION_DENIED");
9601
- C(D.values?.length);
9601
+ A(N.values?.length);
9602
9602
  }
9603
9603
  }
9604
- u?.roles.includes(r.Role) && u.range && C(u.range.fields.length);
9604
+ u?.roles.includes(r.Role) && u.range && A(u.range.fields.length);
9605
9605
  const v = h.admin?.statusField;
9606
- v && !u?.roles.includes(r.Role) && C(Math.max(v.active?.length || 0, v.archived?.length || 0));
9607
- const Z = T === 0 ? 30 : Math.max(1, Math.floor(30 / T)), x = [];
9608
- p.filter((E) => E.type === "Record_Owner").forEach(() => x.push(["Created_By", "==", s])), p.filter((E) => E.type === "Record_User").forEach((E) => {
9609
- if ("collectionField" in E) {
9610
- const D = W(c, E.collectionField);
9611
- x.push([`${D.name}_Array`, "array-contains", r.Doc_ID]);
9606
+ v && !u?.roles.includes(r.Role) && A(Math.max(v.active?.length || 0, v.archived?.length || 0));
9607
+ const j = R === 0 ? 30 : Math.max(1, Math.floor(30 / R)), I = [];
9608
+ p.filter((w) => w.type === "Record_Owner").forEach(() => I.push(["Created_By", "==", s])), p.filter((w) => w.type === "Record_User").forEach((w) => {
9609
+ if ("collectionField" in w) {
9610
+ const N = V(c, w.collectionField);
9611
+ I.push([`${N.name}_Array`, "array-contains", r.Doc_ID]);
9612
9612
  }
9613
- }), p.filter((E) => E.type === "Record_Property").forEach((E) => {
9614
- if ("propertyField" in E) {
9615
- const D = E.roles.find((F) => F.role === r.Role);
9616
- if (!D)
9613
+ }), p.filter((w) => w.type === "Record_Property").forEach((w) => {
9614
+ if ("propertyField" in w) {
9615
+ const N = w.roles.find((C) => C.role === r.Role);
9616
+ if (!N)
9617
9617
  throw new Error("PERMISSION_DENIED");
9618
- const R = W(c, E.propertyField);
9619
- R.type === "Array" ? x.push([`${R.name}_Array`, "array-contains-any", D.values]) : x.push([R.name, "in", D.values]);
9618
+ const T = V(c, w.propertyField);
9619
+ T.type === "Array" ? I.push([`${T.name}_Array`, "array-contains-any", N.values]) : I.push([T.name, "in", N.values]);
9620
9620
  }
9621
9621
  });
9622
9622
  const g = [];
9623
- w.filter((E) => E.type === "Individual").forEach((E) => {
9624
- const D = d?.individualEntities, R = [];
9625
- if (D) {
9626
- const F = E.singleQuery ? E.singleQuery : Z;
9627
- for (let M = 0; M < D.length; M += F) {
9628
- const P = D.slice(M, M + F);
9629
- R.push(P);
9623
+ _.filter((w) => w.type === "Individual").forEach((w) => {
9624
+ const N = d?.individualEntities, T = [];
9625
+ if (N) {
9626
+ const C = w.singleQuery ? w.singleQuery : j;
9627
+ for (let F = 0; F < N.length; F += C) {
9628
+ const W = N.slice(F, F + C);
9629
+ T.push(W);
9630
9630
  }
9631
- if (!E.singleQuery)
9632
- R.forEach((M) => {
9633
- g.push(...N(x.concat([["id", "in", M]])));
9631
+ if (!w.singleQuery)
9632
+ T.forEach((F) => {
9633
+ g.push(...x(I.concat([["id", "in", F]])));
9634
9634
  });
9635
9635
  else {
9636
- if (D.length > F)
9637
- throw new Error(`INPUT_ERROR: Individual entity restriction with singleQuery set to true must not have more than ${E.singleQuery} entities`);
9638
- x.push(["id", "in", D]);
9636
+ if (N.length > C)
9637
+ throw new Error(`INPUT_ERROR: Individual entity restriction with singleQuery set to true must not have more than ${w.singleQuery} entities`);
9638
+ I.push(["id", "in", N]);
9639
9639
  }
9640
9640
  }
9641
- }), b.filter((E) => E.parentFilter.type === "Individual").forEach((E) => {
9642
- const { parentFilter: D, parentRestriction: R } = E;
9643
- if ("collectionField" in D) {
9644
- const F = W(c, D.collectionField);
9645
- if ("collection" in F) {
9646
- const M = r.collections?.[F.collection];
9647
- if (!M)
9641
+ }), S.filter((w) => w.parentFilter.type === "Individual").forEach((w) => {
9642
+ const { parentFilter: N, parentRestriction: T } = w;
9643
+ if ("collectionField" in N) {
9644
+ const C = V(c, N.collectionField);
9645
+ if ("collection" in C) {
9646
+ const F = r.collections?.[C.collection];
9647
+ if (!F)
9648
9648
  throw new Error("PERMISSION_DENIED");
9649
- const P = M.individualEntities, j = [];
9650
- if (P) {
9651
- const Q = R.singleQuery ? R.singleQuery : Z;
9652
- for (let S = 0; S < P.length; S += Q) {
9653
- const q = P.slice(S, S + Q);
9654
- j.push(q);
9649
+ const W = F.individualEntities, U = [];
9650
+ if (W) {
9651
+ const J = T.singleQuery ? T.singleQuery : j;
9652
+ for (let O = 0; O < W.length; O += J) {
9653
+ const z = W.slice(O, O + J);
9654
+ U.push(z);
9655
9655
  }
9656
- if (!R.singleQuery)
9657
- j.forEach((S) => {
9658
- g.push(...N(x.concat([[`${F.name}_Array`, "array-contains-any", S]])));
9656
+ if (!T.singleQuery)
9657
+ U.forEach((O) => {
9658
+ g.push(...x(I.concat([[`${C.name}_Array`, "array-contains-any", O]])));
9659
9659
  });
9660
9660
  else {
9661
- if (P.length > Q)
9662
- throw new Error(`INPUT_ERROR: Individual entity parentFilter with singleQuery set to true must not have more than ${R.singleQuery} entities`);
9663
- x.push([`${F.name}_Array`, "array-contains-any", P]);
9661
+ if (W.length > J)
9662
+ throw new Error(`INPUT_ERROR: Individual entity parentFilter with singleQuery set to true must not have more than ${T.singleQuery} entities`);
9663
+ I.push([`${C.name}_Array`, "array-contains-any", W]);
9664
9664
  }
9665
9665
  }
9666
9666
  }
9667
9667
  }
9668
9668
  });
9669
- const O = [];
9670
- w.filter((E) => E.type === "Parent").forEach((E) => {
9671
- if ("collectionField" in E) {
9672
- const D = W(c, E.collectionField);
9673
- if ("collection" in D) {
9674
- const R = d?.parentEntities, F = [];
9675
- if (R) {
9676
- const M = E.singleQuery ? E.singleQuery : Z;
9677
- for (let P = 0; P < R.length; P += M) {
9678
- const j = R.slice(P, P + M);
9679
- F.push(j);
9669
+ const k = [];
9670
+ _.filter((w) => w.type === "Parent").forEach((w) => {
9671
+ if ("collectionField" in w) {
9672
+ const N = V(c, w.collectionField);
9673
+ if ("collection" in N) {
9674
+ const T = d?.parentEntities, C = [];
9675
+ if (T) {
9676
+ const F = w.singleQuery ? w.singleQuery : j;
9677
+ for (let W = 0; W < T.length; W += F) {
9678
+ const U = T.slice(W, W + F);
9679
+ C.push(U);
9680
9680
  }
9681
- if (!E.singleQuery)
9682
- F.forEach((P) => {
9683
- O.push(...N(x.concat([[`${D.name}_Array`, "array-contains-any", P]])));
9681
+ if (!w.singleQuery)
9682
+ C.forEach((W) => {
9683
+ k.push(...x(I.concat([[`${N.name}_Array`, "array-contains-any", W]])));
9684
9684
  });
9685
9685
  else {
9686
- if (R && R.length > M)
9687
- throw new Error(`INPUT_ERROR: Parent entity restriction with singleQuery set to true must not have more than ${E.singleQuery} entities`);
9688
- x.push([`${D.name}_Array`, "array-contains-any", R]);
9686
+ if (T && T.length > F)
9687
+ throw new Error(`INPUT_ERROR: Parent entity restriction with singleQuery set to true must not have more than ${w.singleQuery} entities`);
9688
+ I.push([`${N.name}_Array`, "array-contains-any", T]);
9689
9689
  }
9690
9690
  }
9691
9691
  }
9692
9692
  }
9693
- }), b.filter((E) => E.parentFilter.type === "Parent").forEach((E) => {
9694
- const { parentFilter: D, parentRestriction: R } = E;
9695
- if ("collectionField" in D && "parentCollectionField" in D) {
9696
- const F = W(c, D.collectionField), M = W(c, D.parentCollectionField);
9697
- if ("collection" in F && "collection" in M) {
9698
- const P = r.collections?.[F.collection];
9699
- if (!P)
9693
+ }), S.filter((w) => w.parentFilter.type === "Parent").forEach((w) => {
9694
+ const { parentFilter: N, parentRestriction: T } = w;
9695
+ if ("collectionField" in N && "parentCollectionField" in N) {
9696
+ const C = V(c, N.collectionField), F = V(c, N.parentCollectionField);
9697
+ if ("collection" in C && "collection" in F) {
9698
+ const W = r.collections?.[C.collection];
9699
+ if (!W)
9700
9700
  throw new Error("PERMISSION_DENIED");
9701
- const j = P.parentEntities, Q = [];
9702
- if (j) {
9703
- const S = R.singleQuery ? R.singleQuery : Z;
9704
- for (let q = 0; q < j.length; q += S) {
9705
- const B = j.slice(q, q + S);
9706
- Q.push(B);
9701
+ const U = W.parentEntities, J = [];
9702
+ if (U) {
9703
+ const O = T.singleQuery ? T.singleQuery : j;
9704
+ for (let z = 0; z < U.length; z += O) {
9705
+ const q = U.slice(z, z + O);
9706
+ J.push(q);
9707
9707
  }
9708
- if (!R.singleQuery)
9709
- Q.forEach((q) => {
9710
- O.push(...N(x.concat([
9711
- [`${M.name}_Array`, "array-contains-any", q]
9708
+ if (!T.singleQuery)
9709
+ J.forEach((z) => {
9710
+ k.push(...x(I.concat([
9711
+ [`${F.name}_Array`, "array-contains-any", z]
9712
9712
  ])));
9713
9713
  });
9714
9714
  else {
9715
- if (j && j.length > S)
9716
- throw new Error(`INPUT_ERROR: Profile_Parent entity parentFilter with singleQuery set to true must not have more than ${R.singleQuery} entities`);
9717
- x.push([
9718
- `${M.name}_Array`,
9715
+ if (U && U.length > O)
9716
+ throw new Error(`INPUT_ERROR: Profile_Parent entity parentFilter with singleQuery set to true must not have more than ${T.singleQuery} entities`);
9717
+ I.push([
9718
+ `${F.name}_Array`,
9719
9719
  "array-contains-any",
9720
- j
9720
+ U
9721
9721
  ]);
9722
9722
  }
9723
9723
  }
9724
9724
  }
9725
9725
  }
9726
9726
  });
9727
- const _ = [];
9728
- O.length === 0 && (w.filter((E) => E.type === "Parent_Property").forEach((E) => {
9729
- if ("collectionField" in E && "propertyField" in E) {
9730
- const D = W(c, E.collectionField), R = W(c, E.propertyField);
9731
- if ("collection" in D) {
9732
- const F = d?.parentPropertyEntities || {};
9733
- Object.entries(F).forEach(([M, P]) => {
9734
- if (P.length > 0) {
9735
- const j = [];
9736
- for (let Q = 0; Q < P.length; Q += Z) {
9737
- const S = P.slice(Q, Q + Z);
9738
- j.push(S);
9727
+ const E = [];
9728
+ k.length === 0 && (_.filter((w) => w.type === "Parent_Property").forEach((w) => {
9729
+ if ("collectionField" in w && "propertyField" in w) {
9730
+ const N = V(c, w.collectionField), T = V(c, w.propertyField);
9731
+ if ("collection" in N) {
9732
+ const C = d?.parentPropertyEntities || {};
9733
+ Object.entries(C).forEach(([F, W]) => {
9734
+ if (W.length > 0) {
9735
+ const U = [];
9736
+ for (let J = 0; J < W.length; J += j) {
9737
+ const O = W.slice(J, J + j);
9738
+ U.push(O);
9739
9739
  }
9740
- j.forEach((Q) => {
9741
- _.push(...N(x.concat([
9742
- [`${D.name}_Array`, "array-contains-any", Q],
9743
- [R.name, "==", M]
9740
+ U.forEach((J) => {
9741
+ E.push(...x(I.concat([
9742
+ [`${N.name}_Array`, "array-contains-any", J],
9743
+ [T.name, "==", F]
9744
9744
  ])));
9745
9745
  });
9746
9746
  }
9747
9747
  });
9748
9748
  }
9749
9749
  }
9750
- }), b.filter((E) => E.parentFilter.type === "Parent_Property").forEach((E) => {
9751
- const { parentFilter: D } = E;
9752
- if ("collectionField" in D && "parentCollectionField" in D && "parentPropertyField" in D) {
9753
- const R = W(c, D.collectionField), F = W(c, D.parentCollectionField), M = W(c, D.parentPropertyField);
9754
- if ("collection" in R && "collection" in F) {
9755
- const P = r.collections?.[R.collection];
9756
- if (!P)
9750
+ }), S.filter((w) => w.parentFilter.type === "Parent_Property").forEach((w) => {
9751
+ const { parentFilter: N } = w;
9752
+ if ("collectionField" in N && "parentCollectionField" in N && "parentPropertyField" in N) {
9753
+ const T = V(c, N.collectionField), C = V(c, N.parentCollectionField), F = V(c, N.parentPropertyField);
9754
+ if ("collection" in T && "collection" in C) {
9755
+ const W = r.collections?.[T.collection];
9756
+ if (!W)
9757
9757
  throw new Error("PERMISSION_DENIED");
9758
- const j = P.parentPropertyEntities || {};
9759
- Object.entries(j).forEach(([Q, S]) => {
9760
- if (S.length > 0) {
9761
- const q = [];
9762
- for (let B = 0; B < S.length; B += Z) {
9763
- const re = S.slice(B, B + Z);
9764
- q.push(re);
9758
+ const U = W.parentPropertyEntities || {};
9759
+ Object.entries(U).forEach(([J, O]) => {
9760
+ if (O.length > 0) {
9761
+ const z = [];
9762
+ for (let q = 0; q < O.length; q += j) {
9763
+ const re = O.slice(q, q + j);
9764
+ z.push(re);
9765
9765
  }
9766
- q.forEach((B) => {
9767
- _.push(...N(x.concat([
9766
+ z.forEach((q) => {
9767
+ E.push(...x(I.concat([
9768
9768
  [
9769
- `${F.name}_Array`,
9769
+ `${C.name}_Array`,
9770
9770
  "array-contains-any",
9771
- B
9771
+ q
9772
9772
  ],
9773
- [M.name, "==", Q]
9773
+ [F.name, "==", J]
9774
9774
  ])));
9775
9775
  });
9776
9776
  }
@@ -9778,8 +9778,8 @@ const Tt = {
9778
9778
  }
9779
9779
  }
9780
9780
  }));
9781
- const A = [...g, ...O, ..._];
9782
- return !w.length && !b.length ? N(x) : A;
9781
+ const B = [...g, ...k, ...E];
9782
+ return !_.length && !S.length ? x(I) : B;
9783
9783
  } else
9784
9784
  throw new Error("PERMISSION_DENIED");
9785
9785
  else return [f];
@@ -9798,8 +9798,8 @@ const Tt = {
9798
9798
  if (h)
9799
9799
  d.push(i.collection("tenants").doc(n).collection("system_fields").doc(l.collection).collection(`${l.collection}-${m.key}`).doc(t));
9800
9800
  else if (f)
9801
- for (const k of f)
9802
- d.push(i.collection("tenants").doc(n).collection("system_fields").doc(l.collection).collection(`${l.collection}-${k.field}`).doc(t));
9801
+ for (const b of f)
9802
+ d.push(i.collection("tenants").doc(n).collection("system_fields").doc(l.collection).collection(`${l.collection}-${b.field}`).doc(t));
9803
9803
  return d;
9804
9804
  } else
9805
9805
  return [c.doc(t)];
@@ -9810,7 +9810,7 @@ const Tt = {
9810
9810
  throw new Error(`SCHEMA_ERROR: Collection ${m} not found in subcollections of ${u}`);
9811
9811
  }) : s.collections = h;
9812
9812
  const f = s.depth - 1, d = s.collections.map(async (m) => {
9813
- const k = await Io([...t, m], s.constraints, {
9813
+ const b = await Io([...t, m], s.constraints, {
9814
9814
  user: a,
9815
9815
  pagination: s.limit,
9816
9816
  providedTransaction: l,
@@ -9818,7 +9818,7 @@ const Tt = {
9818
9818
  }).catch((y) => {
9819
9819
  throw y.code === "permission-denied" && console.info(`PERMISSION_DENIED for subcollection ${m} for document at ${t.join("/")}`), y;
9820
9820
  });
9821
- e[m] = k.docs, i && await Promise.all(
9821
+ e[m] = b.docs, i && await Promise.all(
9822
9822
  // eslint-disable-next-line security/detect-object-injection
9823
9823
  e[m].map((y) => Xs(n, y, [...t, m, y.id], i, r, void 0, a, l, c))
9824
9824
  ), f > 0 && await Promise.all(
@@ -9837,18 +9837,18 @@ const Tt = {
9837
9837
  if (!d)
9838
9838
  continue;
9839
9839
  const m = Object.keys(d);
9840
- for (const k of m) {
9841
- const y = d[k], w = at(y.Collection_Path, k, {
9840
+ for (const b of m) {
9841
+ const y = d[b], _ = at(y.Collection_Path, b, {
9842
9842
  user: o,
9843
9843
  providedTransaction: a,
9844
9844
  noEmbeddingFields: l
9845
- }).then((b) => {
9846
- if (d[k] = b, u > 0)
9845
+ }).then((S) => {
9846
+ if (d[b] = S, u > 0)
9847
9847
  return Xs(
9848
9848
  n,
9849
9849
  // eslint-disable-next-line security/detect-object-injection
9850
- d[k],
9851
- [...y.Collection_Path, k],
9850
+ d[b],
9851
+ [...y.Collection_Path, b],
9852
9852
  { depth: u },
9853
9853
  r,
9854
9854
  i,
@@ -9856,13 +9856,13 @@ const Tt = {
9856
9856
  a,
9857
9857
  l
9858
9858
  );
9859
- }).catch((b) => {
9860
- if (b.message.includes("NOT_FOUND") || b.code === "permission-denied")
9861
- delete d[k];
9859
+ }).catch((S) => {
9860
+ if (S.message.includes("NOT_FOUND") || S.code === "permission-denied")
9861
+ delete d[b];
9862
9862
  else
9863
- throw b;
9863
+ throw S;
9864
9864
  });
9865
- h.push(w);
9865
+ h.push(_);
9866
9866
  }
9867
9867
  }
9868
9868
  await Promise.all(h);
@@ -9889,67 +9889,69 @@ const Tt = {
9889
9889
  if (h.data().active)
9890
9890
  throw new Error("MAINTENANCE_MODE");
9891
9891
  const m = f;
9892
- let k;
9893
- const y = Ut(), w = n.at(-1);
9894
- if (!w)
9892
+ let b;
9893
+ const y = Ut(), _ = n.at(-1);
9894
+ if (!_)
9895
9895
  throw new Error("EMPTY_PATH");
9896
- const b = Object.keys(m.collections).includes(w), N = y.disabledCollections?.includes(w);
9897
- if (!b || N)
9896
+ const S = Object.keys(m.collections).includes(_), x = y.disabledCollections?.includes(_);
9897
+ if (!S || x)
9898
9898
  throw new Error("COLLECTION_NOT_FOUND");
9899
- const p = m.collections[w], { labels: T } = p, C = Je(T.collection, m);
9899
+ const p = m.collections[_], { labels: R } = p, A = Je(R.collection, m);
9900
9900
  if (t?.user) {
9901
9901
  if (!u?.exists)
9902
9902
  throw new Error("PERMISSION_DENIED");
9903
- if (k = u.data(), !k.Role)
9903
+ if (b = u.data(), !b.Role)
9904
9904
  throw new Error("USER_ERROR");
9905
- if (!k.Enabled)
9905
+ if (!b.Enabled)
9906
9906
  throw new Error("PERMISSION_DENIED");
9907
9907
  }
9908
- let v = Vc(s, n, m, t?.user, k);
9908
+ let v = Vc(s, n, m, t?.user, b);
9909
9909
  if (v.length === 0)
9910
9910
  return { cursor: {}, pages: 0, docs: [] };
9911
- if (e && (v = v.map((A) => (e.forEach(([E, D, R]) => {
9912
- A = A.where(E, D, R);
9913
- }), A))), o = t?.pagination?.startAfter || t?.pagination?.endBefore || {
9911
+ if (e && (v = v.map((w) => (e.forEach(([N, T, C]) => {
9912
+ w = w.where(N, T, C);
9913
+ }), w))), o = t?.pagination?.startAfter || t?.pagination?.endBefore || {
9914
9914
  first: /* @__PURE__ */ new Map(),
9915
9915
  last: /* @__PURE__ */ new Map()
9916
9916
  }, t?.pagination) {
9917
9917
  if (t.pagination.startAfter && t.pagination.endBefore)
9918
9918
  throw new Error("INPUT_ERROR: startAfter and endBefore cannot be provided together");
9919
- const A = t.pagination.startAfter || t.pagination.endBefore;
9919
+ const w = t.pagination.startAfter || t.pagination.endBefore;
9920
9920
  if (t?.user) {
9921
- const E = ta(k.Role, p, m);
9922
- if (A && E !== !0)
9923
- throw new Error("INPUT_ERROR: Pagination is not allowed when using " + E);
9921
+ const N = ta(b.Role, p, m);
9922
+ if (w && N !== !0)
9923
+ throw new Error("INPUT_ERROR: Pagination is not allowed when using " + N);
9924
9924
  }
9925
- t.pagination.orderByField && t.pagination.orderByDirection ? !t.pagination.startAfter && !t.pagination.endBefore ? v = v.map((E) => E.orderBy(t.pagination.orderByField, t.pagination.orderByDirection).limit(t.pagination.number)) : t.pagination.startAfter ? v = v.map((E, D) => E.orderBy(t.pagination.orderByField, t.pagination.orderByDirection).startAfter(o.last.get(D)).limit(t.pagination.number)) : v = v.map((E, D) => E.orderBy(t.pagination.orderByField, t.pagination.orderByDirection).endBefore(o.first.get(D)).limitToLast(t.pagination.number)) : !t.pagination.startAfter && !t.pagination.endBefore ? v = v.map((E) => E.limit(t.pagination.number)) : t.pagination.startAfter ? v = v.map((E, D) => E.startAfter(o.last.get(D)).limit(t.pagination.number)) : v = v.map((E, D) => E.endBefore(o.first.get(D)).limitToLast(t.pagination.number));
9925
+ t.pagination.orderByField && t.pagination.orderByDirection ? !t.pagination.startAfter && !t.pagination.endBefore ? v = v.map((N) => N.orderBy(t.pagination.orderByField, t.pagination.orderByDirection).limit(t.pagination.number)) : t.pagination.startAfter ? v = v.map((N, T) => N.orderBy(t.pagination.orderByField, t.pagination.orderByDirection).startAfter(o.last.get(T)).limit(t.pagination.number)) : v = v.map((N, T) => N.orderBy(t.pagination.orderByField, t.pagination.orderByDirection).endBefore(o.first.get(T)).limitToLast(t.pagination.number)) : !t.pagination.startAfter && !t.pagination.endBefore ? v = v.map((N) => N.limit(t.pagination.number)) : t.pagination.startAfter ? v = v.map((N, T) => N.startAfter(o.last.get(T)).limit(t.pagination.number)) : v = v.map((N, T) => N.endBefore(o.first.get(T)).limitToLast(t.pagination.number));
9926
9926
  }
9927
- const Z = {};
9928
- await ae("preOperation", y, C, ["read", void 0, void 0, Z]), await ae("preRead", y, C, [Z, v, !0, !1]), a = /* @__PURE__ */ new Map();
9929
- const O = v.map(async (A) => await c.get(A)), _ = await Promise.all(O);
9930
- for (const A of _) {
9931
- for (const E of A.docs) {
9932
- a.has(E.id) || a.set(E.id, {});
9933
- const D = E.data(), R = a.get(E.id);
9934
- R.id ||= E.id;
9935
- const F = { ...R, ...D };
9936
- delete F.Collection_Path_String, a.set(E.id, F);
9927
+ const j = {};
9928
+ await ae("preOperation", y, A, ["read", void 0, void 0, j]), await ae("preRead", y, A, [j, v, !0, !1]), a = /* @__PURE__ */ new Map();
9929
+ const k = v.map(async (w) => await c.get(w)), E = await Promise.all(k);
9930
+ for (const w of E) {
9931
+ for (const N of w.docs) {
9932
+ a.has(N.id) || a.set(N.id, {});
9933
+ const T = N.data(), C = a.get(N.id);
9934
+ C.id ||= N.id;
9935
+ const F = { ...C, ...T };
9936
+ delete F.Collection_Path_String, a.set(N.id, F);
9937
9937
  }
9938
- o.first.set(_.indexOf(A), A.docs[0]), o.last.set(_.indexOf(A), A.docs.at(-1) || A.docs[0]);
9938
+ o.first.set(E.indexOf(w), w.docs[0]), o.last.set(E.indexOf(w), w.docs.at(-1) || w.docs[0]);
9939
9939
  }
9940
9940
  if (t?.pagination) {
9941
- let A = v[0];
9942
- e && (A = e.reduce((F, [M, P, j]) => F.where(M, P, j), A)), t.pagination.orderByField && t.pagination.orderByDirection && (A = A.orderBy(t.pagination.orderByField, t.pagination.orderByDirection));
9943
- const D = (await A.count().get()).data().count, R = t.pagination.number;
9944
- i = R > 0 ? Math.ceil(D / R) : 0;
9941
+ let w = v[0];
9942
+ e && (w = e.reduce((F, [W, U, J]) => F.where(W, U, J), w)), t.pagination.orderByField && t.pagination.orderByDirection && (w = w.orderBy(t.pagination.orderByField, t.pagination.orderByDirection));
9943
+ const T = (await w.count().get()).data().count, C = t.pagination.number;
9944
+ i = C > 0 ? Math.ceil(T / C) : 0;
9945
9945
  }
9946
- for (const A of a.values()) {
9947
- const E = [], D = [...A.Collection_Path, A.id];
9948
- t?.subcollections && E.push(xo(
9946
+ let B;
9947
+ t?.noComputedFields || (B = await ie(A.admin?.retriever));
9948
+ for (const w of a.values()) {
9949
+ const N = [], T = [...w.Collection_Path, w.id];
9950
+ t?.subcollections && N.push(xo(
9949
9951
  s,
9950
9952
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
9951
- a.get(A.id),
9952
- D,
9953
+ a.get(w.id),
9954
+ T,
9953
9955
  ye(t.subcollections),
9954
9956
  m,
9955
9957
  ye(t?.relations),
@@ -9957,51 +9959,53 @@ const Tt = {
9957
9959
  t.user,
9958
9960
  t.transactional ? c : void 0,
9959
9961
  t?.noEmbeddingFields
9960
- )), t?.relations && (t.relations.fields && (t.relations.fields = t.relations.fields.map((M) => {
9961
- if (typeof M == "string") {
9962
- const P = p.fields.find((j) => j.name === M);
9963
- if (P)
9964
- return P;
9965
- throw new Error(`SCHEMA_ERROR: Field ${M} not found in collection ${w}`);
9962
+ )), t?.relations && (t.relations.fields && (t.relations.fields = t.relations.fields.map((U) => {
9963
+ if (typeof U == "string") {
9964
+ const J = p.fields.find((O) => O.name === U);
9965
+ if (J)
9966
+ return J;
9967
+ throw new Error(`SCHEMA_ERROR: Field ${U} not found in collection ${_}`);
9966
9968
  }
9967
- return M;
9968
- })), E.push(Xs(
9969
+ return U;
9970
+ })), N.push(Xs(
9969
9971
  s,
9970
9972
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
9971
- a.get(A.id),
9972
- D,
9973
+ a.get(w.id),
9974
+ T,
9973
9975
  ye(t.relations),
9974
9976
  m,
9975
9977
  void 0,
9976
9978
  t.user,
9977
9979
  t.transactional ? c : void 0,
9978
9980
  t?.noEmbeddingFields
9979
- ))), await Promise.all(E);
9980
- for (const M of a.values())
9981
- for (const P of p.fields) {
9982
- if (P.type === "Computed") {
9983
- const j = Ie(P, C);
9984
- if (!j.formula)
9985
- continue;
9986
- M[P.name] = await j.formula(M);
9987
- }
9988
- t?.noEmbeddingFields && P.type === "Embedding" && delete M[P.name];
9981
+ ))), await Promise.all(N);
9982
+ const C = [];
9983
+ for (const U of p.fields) {
9984
+ if (U.type === "Computed" && !t?.noComputedFields) {
9985
+ const J = Ie(U, A);
9986
+ if (!J.formula)
9987
+ continue;
9988
+ C.push(ie(J.formula, [w, B]).then((O) => {
9989
+ w[U.name] = O;
9990
+ }));
9989
9991
  }
9990
- if (t?.user && k?.Role) {
9991
- const M = k.Role;
9992
- if (!(C.custom?.serverAccess?.read !== void 0 ? await ie(C.custom.serverAccess.read, [M, A]) : !0)) {
9993
- a.delete(A.id);
9992
+ t?.noEmbeddingFields && U.type === "Embedding" && delete w[U.name];
9993
+ }
9994
+ if (await Promise.all(C), t?.user && b?.Role) {
9995
+ const U = b.Role;
9996
+ if (!(A.custom?.serverAccess?.read !== void 0 ? await ie(A.custom.serverAccess.read, [U, w]) : !0)) {
9997
+ a.delete(w.id);
9994
9998
  continue;
9995
9999
  }
9996
- for (const j of p.fields) {
9997
- const Q = !j.access || j.access.includes(M), S = Ie(j, C), q = S?.custom?.serverAccess?.read !== void 0 ? await ie(S.custom.serverAccess.read, [M, A]) : !0;
9998
- (!Q || !q) && (K(j) ? (delete a.get(A.id)[j.name], delete a.get(A.id)[`${j.name}_Array`], delete a.get(A.id)[`${j.name}_Single`]) : delete a.get(A.id)[j.name]);
10000
+ for (const O of p.fields) {
10001
+ const z = !O.access || O.access.includes(U), q = Ie(O, A), re = q?.custom?.serverAccess?.read !== void 0 ? await ie(q.custom.serverAccess.read, [U, w]) : !0;
10002
+ (!z || !re) && (K(O) ? (delete a.get(w.id)[O.name], delete a.get(w.id)[`${O.name}_Array`], delete a.get(w.id)[`${O.name}_Single`]) : delete a.get(w.id)[O.name]);
9999
10003
  }
10000
10004
  }
10001
- const R = ["read", A, A.id, Z];
10002
- await ae("postOperation", y, C, R), await ae("postRead", y, C, [Z, v, A, !1]);
10005
+ const F = ["read", w, w.id, j];
10006
+ await ae("postOperation", y, A, F), await ae("postRead", y, A, [j, v, w, !1]);
10003
10007
  }
10004
- t?.user && await Xo(Array.from(a.values()), p, m, t.user, k);
10008
+ t?.user && await Xo(Array.from(a.values()), p, m, t.user, b);
10005
10009
  };
10006
10010
  return t?.providedTransaction ? await l(t.providedTransaction) : await r.runTransaction(async (c) => {
10007
10011
  await l(c);
@@ -10038,31 +10042,31 @@ const Tt = {
10038
10042
  const d = t[f.name];
10039
10043
  if (!d)
10040
10044
  continue;
10041
- for (const [m, k] of Object.entries(d)) {
10042
- const y = at(k.Collection_Path, m, {
10045
+ for (const [m, b] of Object.entries(d)) {
10046
+ const y = at(b.Collection_Path, m, {
10043
10047
  user: o,
10044
10048
  providedTransaction: e,
10045
10049
  noComputedFields: a,
10046
10050
  noEmbeddingFields: l
10047
- }).then((w) => {
10048
- if (d[m] = w, u > 0)
10051
+ }).then((_) => {
10052
+ if (d[m] = _, u > 0)
10049
10053
  return Ao(
10050
10054
  n,
10051
10055
  e,
10052
10056
  // eslint-disable-next-line security/detect-object-injection
10053
10057
  d[m],
10054
- [...k.Collection_Path, m],
10058
+ [...b.Collection_Path, m],
10055
10059
  r,
10056
10060
  { depth: u },
10057
10061
  o,
10058
10062
  a,
10059
10063
  l
10060
10064
  );
10061
- }).catch((w) => {
10062
- if (w.message.includes("NOT_FOUND") || w.code === "permission-denied")
10065
+ }).catch((_) => {
10066
+ if (_.message.includes("NOT_FOUND") || _.code === "permission-denied")
10063
10067
  delete d[m];
10064
10068
  else
10065
- throw w;
10069
+ throw _;
10066
10070
  });
10067
10071
  h.push(y);
10068
10072
  }
@@ -10087,14 +10091,14 @@ const Tt = {
10087
10091
  throw new Error("MAINTENANCE_MODE");
10088
10092
  const f = u;
10089
10093
  let d;
10090
- const m = Ut(), k = n.at(-1);
10091
- if (!k)
10094
+ const m = Ut(), b = n.at(-1);
10095
+ if (!b)
10092
10096
  throw new Error("EMPTY_PATH");
10093
- const y = Object.keys(f.collections).includes(k), w = m.disabledCollections?.includes(k);
10094
- if (!y || w)
10097
+ const y = Object.keys(f.collections).includes(b), _ = m.disabledCollections?.includes(b);
10098
+ if (!y || _)
10095
10099
  throw new Error("COLLECTION_NOT_FOUND");
10096
- const b = f.collections[k], { labels: N } = b, p = Je(N.collection, f);
10097
- let T;
10100
+ const S = f.collections[b], { labels: x } = S, p = Je(x.collection, f);
10101
+ let R;
10098
10102
  if (t?.user) {
10099
10103
  if (!l?.exists)
10100
10104
  throw new Error("PERMISSION_DENIED");
@@ -10102,54 +10106,54 @@ const Tt = {
10102
10106
  throw new Error("USER_ERROR");
10103
10107
  if (!d.Enabled)
10104
10108
  throw new Error("PERMISSION_DENIED");
10105
- if (T = d.collections?.[N.collection], !T)
10109
+ if (R = d.collections?.[x.collection], !R)
10106
10110
  throw new Error("PERMISSION_DENIED");
10107
10111
  }
10108
- if (t?.user && (!T || !Te("Read", T)))
10112
+ if (t?.user && (!R || !Te("Read", R)))
10109
10113
  throw new Error("PERMISSION_DENIED");
10110
- const C = No(s, n, e, f, d);
10111
- if (C.length === 0)
10114
+ const A = No(s, n, e, f, d);
10115
+ if (A.length === 0)
10112
10116
  throw new Error("PERMISSION_DENIED");
10113
10117
  const v = {};
10114
- await ae("preOperation", m, p, ["read", void 0, e, v]), await ae("preRead", m, p, [v, C, !1, !1]), i = {};
10115
- const g = C.map((R) => a.get(R)), O = await Promise.all(g);
10116
- for (const R of O)
10117
- if (R.exists) {
10118
- const F = R.data();
10119
- i.id ||= R.id, i = { ...i, ...F }, delete i.Collection_Path_String;
10118
+ await ae("preOperation", m, p, ["read", void 0, e, v]), await ae("preRead", m, p, [v, A, !1, !1]), i = {};
10119
+ const g = A.map((T) => a.get(T)), k = await Promise.all(g);
10120
+ for (const T of k)
10121
+ if (T.exists) {
10122
+ const C = T.data();
10123
+ i.id ||= T.id, i = { ...i, ...C }, delete i.Collection_Path_String;
10120
10124
  } else
10121
- throw new Error(`NOT_FOUND: Document with ID ${e} does not exist at location ${n?.join("/") || N.collection}`);
10122
- const _ = [], A = n ? [...n, e] : [N.collection, e];
10123
- if (t?.subcollections && _.push(Do(s, a, i, A, t.subcollections, f, void 0, t.user)), t?.relations && (t.relations.fields && (t.relations.fields = t.relations.fields.map((R) => {
10124
- if (typeof R == "string") {
10125
- const F = b.fields.find((M) => M.name === R);
10126
- if (F)
10127
- return F;
10128
- throw new Error(`SCHEMA_ERROR: Field ${R} not found in collection ${k}`);
10125
+ throw new Error(`NOT_FOUND: Document with ID ${e} does not exist at location ${n?.join("/") || x.collection}`);
10126
+ const E = [], B = n ? [...n, e] : [x.collection, e];
10127
+ if (t?.subcollections && E.push(Do(s, a, i, B, t.subcollections, f, void 0, t.user)), t?.relations && (t.relations.fields && (t.relations.fields = t.relations.fields.map((T) => {
10128
+ if (typeof T == "string") {
10129
+ const C = S.fields.find((F) => F.name === T);
10130
+ if (C)
10131
+ return C;
10132
+ throw new Error(`SCHEMA_ERROR: Field ${T} not found in collection ${b}`);
10129
10133
  }
10130
- return R;
10131
- })), _.push(Ao(s, a, i, A, f, t.relations, t.user, t.noComputedFields, t.noEmbeddingFields))), await Promise.all(_), !t?.noComputedFields) {
10132
- for (const R of b.fields)
10133
- if (R.type === "Computed") {
10134
- const F = Ie(R, p);
10135
- if (!F.formula)
10134
+ return T;
10135
+ })), E.push(Ao(s, a, i, B, f, t.relations, t.user, t.noComputedFields, t.noEmbeddingFields))), await Promise.all(E), !t?.noComputedFields) {
10136
+ for (const T of S.fields)
10137
+ if (T.type === "Computed") {
10138
+ const C = Ie(T, p);
10139
+ if (!C.formula)
10136
10140
  continue;
10137
- i[R.name] = await F.formula(i);
10141
+ i[T.name] = await C.formula(i);
10138
10142
  }
10139
10143
  }
10140
10144
  if (t?.noEmbeddingFields)
10141
- for (const R of b.fields)
10142
- R.type === "Embedding" && delete i[R.name];
10145
+ for (const T of S.fields)
10146
+ T.type === "Embedding" && delete i[T.name];
10143
10147
  if (t?.user && d?.Role) {
10144
- const R = d.Role;
10145
- if (!(p.custom?.serverAccess?.read !== void 0 ? await ie(p.custom?.serverAccess?.read, [R, i]) : !0))
10148
+ const T = d.Role;
10149
+ if (!(p.custom?.serverAccess?.read !== void 0 ? await ie(p.custom?.serverAccess?.read, [T, i]) : !0))
10146
10150
  throw new Error("PERMISSION_DENIED");
10147
- for (const M of b.fields) {
10148
- const P = !M.access || M.access.includes(R), j = Ie(M, p), Q = j?.custom?.serverAccess?.read !== void 0 ? await ie(j.custom.serverAccess.read, [R, i]) : !0;
10149
- (!P || !Q) && (K(M) ? (delete i[M.name], delete i[`${M.name}_Array`], delete i[`${M.name}_Single`]) : delete i[M.name]);
10151
+ for (const F of S.fields) {
10152
+ const W = !F.access || F.access.includes(T), U = Ie(F, p), J = U?.custom?.serverAccess?.read !== void 0 ? await ie(U.custom.serverAccess.read, [T, i]) : !0;
10153
+ (!W || !J) && (K(F) ? (delete i[F.name], delete i[`${F.name}_Array`], delete i[`${F.name}_Single`]) : delete i[F.name]);
10150
10154
  }
10151
10155
  }
10152
- await ae("postOperation", m, p, ["read", i, e, v]), await ae("postRead", m, p, [v, C, i, !1]), t?.user && await Ko(i, b, f, t.user, d);
10156
+ await ae("postOperation", m, p, ["read", i, e, v]), await ae("postRead", m, p, [v, A, i, !1]), t?.user && await Ko(i, S, f, t.user, d);
10153
10157
  };
10154
10158
  return t?.providedTransaction ? await o(t.providedTransaction) : await r.runTransaction(async (a) => {
10155
10159
  await o(a);
@@ -10165,8 +10169,8 @@ const Tt = {
10165
10169
  if (!Ks(m))
10166
10170
  f.push(`${d.name} "${s[d.name]}" is invalid`);
10167
10171
  else {
10168
- const k = await l.collection("tenants").doc(e).collection("system_unique").doc(u).collection(`Unique-${u}-${d.name}`).doc(m).get();
10169
- k.exists && !(n === "update" && k.data().id === t) && f.push(`${d.name} "${s[d.name]}" already exists`);
10172
+ const b = await l.collection("tenants").doc(e).collection("system_unique").doc(u).collection(`Unique-${u}-${d.name}`).doc(m).get();
10173
+ b.exists && !(n === "update" && b.data().id === t) && f.push(`${d.name} "${s[d.name]}" already exists`);
10170
10174
  }
10171
10175
  }
10172
10176
  })), f.length > 0)
@@ -10187,13 +10191,13 @@ const Tt = {
10187
10191
  data: {}
10188
10192
  };
10189
10193
  if (f) {
10190
- const w = /* @__PURE__ */ new Date(), b = new Date((/* @__PURE__ */ new Date()).setDate(w.getDate() + f));
10191
- d.TTL = lt.fromDate(b);
10194
+ const _ = /* @__PURE__ */ new Date(), S = new Date((/* @__PURE__ */ new Date()).setDate(_.getDate() + f));
10195
+ d.TTL = lt.fromDate(S);
10192
10196
  }
10193
10197
  const m = ye(t);
10194
10198
  nt(m), n !== "delete" && (d.data.data = ye(m)), n === "update" && (d.data.originalRecord = ye(l)), n !== "delete" && ["started", "written"].includes(e) && (delete d.data.data.Saved_At, delete d.data.data.Last_Save_At), e === "failed" && (d.data.error = JSON.stringify(a));
10195
- const k = De(u, r, s), y = t.Last_Write_At;
10196
- await k.doc(i).collection("system_write_log").doc(`${t.Last_Write_By}-${y.valueOf()}`).set(d);
10199
+ const b = De(u, r, s), y = t.Last_Write_At;
10200
+ await b.doc(i).collection("system_write_log").doc(`${t.Last_Write_By}-${y.valueOf()}`).set(d);
10197
10201
  }, un = async (n) => {
10198
10202
  const e = Ye(), t = gt(), s = ue(), r = [];
10199
10203
  if (await Promise.all([
@@ -10224,19 +10228,19 @@ ${i}`);
10224
10228
  n = h;
10225
10229
  else
10226
10230
  throw new Error("Admin email not set");
10227
- const f = hs(n), d = Pc(e), m = t ? Kr(t) : void 0, k = s ? Kr(s) : void 0, y = r ? hs(r) : void 0, w = i ? hs(i) : void 0, b = o ? Un(o) : void 0, N = l ? Un(l) : void 0, p = Array.isArray(f) ? f : [f];
10231
+ const f = hs(n), d = Pc(e), m = t ? Kr(t) : void 0, b = s ? Kr(s) : void 0, y = r ? hs(r) : void 0, _ = i ? hs(i) : void 0, S = o ? Un(o) : void 0, x = l ? Un(l) : void 0, p = Array.isArray(f) ? f : [f];
10228
10232
  if (p.length === 0 || p.length === 1 && !p[0])
10229
10233
  throw new Error("No valid email addresses provided");
10230
- const T = { to: f, message: { subject: d } };
10231
- if (m && (T.message.text = m), k && (T.message.html = k), y) {
10232
- const C = Array.isArray(y) ? y : [y];
10233
- C.length > 0 && C[0] && (T.cc = y);
10234
+ const R = { to: f, message: { subject: d } };
10235
+ if (m && (R.message.text = m), b && (R.message.html = b), y) {
10236
+ const A = Array.isArray(y) ? y : [y];
10237
+ A.length > 0 && A[0] && (R.cc = y);
10234
10238
  }
10235
- if (w) {
10236
- const C = Array.isArray(w) ? w : [w];
10237
- C.length > 0 && C[0] && (T.bcc = w);
10239
+ if (_) {
10240
+ const A = Array.isArray(_) ? _ : [_];
10241
+ A.length > 0 && A[0] && (R.bcc = _);
10238
10242
  }
10239
- b && (T.replyTo = b), a && (T.message.attachments = a), N && (T.from = N), await c.collection("system_mail").add(T);
10243
+ S && (R.replyTo = S), a && (R.message.attachments = a), x && (R.from = x), await c.collection("system_mail").add(R);
10240
10244
  }, Mo = async (n, e, t, s, r, i, o) => {
10241
10245
  const a = gt(), l = ue(), c = "USER_ERROR", u = async (d, m) => {
10242
10246
  try {
@@ -10292,7 +10296,7 @@ ${i}`);
10292
10296
  d = d.replace("apiKey=&", `apiKey=${m.apiKey}&`);
10293
10297
  }
10294
10298
  if (d) {
10295
- const m = `https://${a.app.options.projectId}.firebaseapp.com/__/auth/action${d}`, k = await ie(t.appName), y = t?.mail?.emailVerification && t.mail.emailVerification(m, k);
10299
+ const m = `https://${a.app.options.projectId}.firebaseapp.com/__/auth/action${d}`, b = await ie(t.appName), y = t?.mail?.emailVerification && t.mail.emailVerification(m, b);
10296
10300
  try {
10297
10301
  await $o(r.Email, y?.subject || "Please verify your email address", void 0, y?.html || `Please verify your email address by clicking the link:
10298
10302
  </br>
@@ -10341,7 +10345,7 @@ ${i}`);
10341
10345
  return t.includeFields.forEach((r) => {
10342
10346
  if (e[r] !== void 0) {
10343
10347
  s[r] = e[r];
10344
- const i = W(n.fields, r);
10348
+ const i = V(n.fields, r);
10345
10349
  wt(n, [i]).size === 1 && (s[`${r}_Lowercase`] = e[`${r}_Lowercase`]);
10346
10350
  }
10347
10351
  }), s;
@@ -10362,8 +10366,8 @@ ${i}`);
10362
10366
  const d = await r.get(f.doc(u));
10363
10367
  if (!d.exists)
10364
10368
  throw new Error(`VALIDATION_ERROR: Record ${u} not found in collection ${t.collection}`);
10365
- const m = d.data(), k = W(a, t.enforceHierarchy.field), y = t.enforceHierarchy;
10366
- if (!m[y.recordLinkField] || !s[k.name] || !Object.keys(s[k.name]).every((w) => Object.keys(m[y.recordLinkField]).includes(w)))
10369
+ const m = d.data(), b = V(a, t.enforceHierarchy.field), y = t.enforceHierarchy;
10370
+ if (!m[y.recordLinkField] || !s[b.name] || !Object.keys(s[b.name]).every((_) => Object.keys(m[y.recordLinkField]).includes(_)))
10367
10371
  throw new Error("VALIDATION_ERROR: Invalid relation hierarchy");
10368
10372
  }, gn = async (n, e, t) => {
10369
10373
  delete e[n.name][t], e[`${n.name}_Array`] = e[`${n.name}_Array`]?.filter((s) => s !== t), delete e[`${n.name}_Single`];
@@ -10375,151 +10379,151 @@ ${i}`);
10375
10379
  K(l) && l.twoWay && l.collection === t && ((n === "Create" || !i?.[l.name]?.[e]) && r[l.name]?.[e] && o.push(l), n === "Update" && i?.[l.name]?.[e] && !r[l.name]?.[e] && a.push(l));
10376
10380
  return { addedFields: o, removedFields: a };
10377
10381
  }, Po = async (n, e, t, s, r, i, o, a, l, c, u, h) => {
10378
- const { fields: f } = i, d = ue(), m = /* @__PURE__ */ new Map(), k = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map();
10379
- for (const w of f)
10380
- K(w) && ["OneToOne", "OneToMany"].includes(w.type) && w.enforceHierarchy && s[w.name] && (n === "Create" || n === "Update" && !ze(h?.[w.name], s[w.name])) && await ei(e, i, w, s, a, l);
10381
- for (const w of f)
10382
- if (K(w) && w.twoWay) {
10383
- const b = o.collections[w.collection], N = W(b.fields, w.twoWay), p = ft(b, [N]);
10384
- if (s[w.name]) {
10385
- const T = Object.entries(s[w.name]);
10386
- for (const C of T) {
10387
- const [v, Z] = C;
10388
- if (n === "Create" || !h?.[w.name]?.[v]) {
10389
- let x;
10390
- const g = y.get(w.collection)?.[v];
10382
+ const { fields: f } = i, d = ue(), m = /* @__PURE__ */ new Map(), b = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map();
10383
+ for (const _ of f)
10384
+ K(_) && ["OneToOne", "OneToMany"].includes(_.type) && _.enforceHierarchy && s[_.name] && (n === "Create" || n === "Update" && !ze(h?.[_.name], s[_.name])) && await ei(e, i, _, s, a, l);
10385
+ for (const _ of f)
10386
+ if (K(_) && _.twoWay) {
10387
+ const S = o.collections[_.collection], x = V(S.fields, _.twoWay), p = ft(S, [x]);
10388
+ if (s[_.name]) {
10389
+ const R = Object.entries(s[_.name]);
10390
+ for (const A of R) {
10391
+ const [v, j] = A;
10392
+ if (n === "Create" || !h?.[_.name]?.[v]) {
10393
+ let I;
10394
+ const g = y.get(_.collection)?.[v];
10391
10395
  if (g)
10392
- x = g;
10396
+ I = g;
10393
10397
  else {
10394
10398
  l.size++, l && l.size > 500 && console.error(new Error(`VALIDATION_ERROR: ${l.size} operations in the Firestore transaction has exceeded the limit of 500. This is likely due to a large number of two way updates, unique field checks, entity restrictions (in permissions when dealing with user collections) or relation hierarchy checks.`));
10395
- const _ = De(d, Z.Collection_Path, e), A = await a.get(_.doc(v));
10396
- if (!A.exists) {
10397
- gn(w, r, v);
10399
+ const E = De(d, j.Collection_Path, e), B = await a.get(E.doc(v));
10400
+ if (!B.exists) {
10401
+ gn(_, r, v);
10398
10402
  continue;
10399
10403
  }
10400
- const E = A.data();
10401
- k.set(w.collection, {
10402
- ...k.get(w.collection) || {},
10403
- [v]: E
10404
- }), x = ye({ ...E, ...Sn(s) });
10404
+ const w = B.data();
10405
+ b.set(_.collection, {
10406
+ ...b.get(_.collection) || {},
10407
+ [v]: w
10408
+ }), I = ye({ ...w, ...Sn(s) });
10405
10409
  }
10406
- const O = {
10407
- ...x[N.name],
10410
+ const k = {
10411
+ ...I[x.name],
10408
10412
  [t]: {
10409
10413
  Collection_Path: s.Collection_Path,
10410
- ...Uc(i, s, N)
10414
+ ...Uc(i, s, x)
10411
10415
  }
10412
10416
  };
10413
- x[N.name] = O, x[`${N.name}_Array`] ||= [], x[`${N.name}_Array`].push(t), p.size === 1 && (x[`${N.name}_Single`] = O), y.set(w.collection, {
10414
- ...y.get(w.collection) || {},
10415
- [v]: x
10417
+ I[x.name] = k, I[`${x.name}_Array`] ||= [], I[`${x.name}_Array`].push(t), p.size === 1 && (I[`${x.name}_Single`] = k), y.set(_.collection, {
10418
+ ...y.get(_.collection) || {},
10419
+ [v]: I
10416
10420
  });
10417
10421
  }
10418
10422
  }
10419
10423
  }
10420
10424
  if (n === "Update") {
10421
- const T = Object.entries(h?.[w.name] || {});
10422
- for (const C of T) {
10423
- const [v, Z] = C;
10424
- if (!s[w.name]?.[v]) {
10425
- let x;
10426
- const g = y.get(w.collection)?.[v];
10425
+ const R = Object.entries(h?.[_.name] || {});
10426
+ for (const A of R) {
10427
+ const [v, j] = A;
10428
+ if (!s[_.name]?.[v]) {
10429
+ let I;
10430
+ const g = y.get(_.collection)?.[v];
10427
10431
  if (g)
10428
- x = g;
10432
+ I = g;
10429
10433
  else {
10430
10434
  l.size++, l && l.size > 500 && console.error(new Error(`VALIDATION_ERROR: ${l.size} operations in the Firestore transaction has exceeded the limit of 500. This is likely due to a large number of two way updates, unique field checks, entity restrictions (in permissions when dealing with user collections) or relation hierarchy checks.`));
10431
- const O = De(d, Z.Collection_Path, e), _ = await a.get(O.doc(v));
10432
- if (!_.exists) {
10433
- m.set(w.name, [...m.get(w.name) || [], v]);
10435
+ const k = De(d, j.Collection_Path, e), E = await a.get(k.doc(v));
10436
+ if (!E.exists) {
10437
+ m.set(_.name, [...m.get(_.name) || [], v]);
10434
10438
  continue;
10435
10439
  }
10436
- const A = _.data();
10437
- k.set(w.collection, {
10438
- ...k.get(w.collection) || {},
10439
- [v]: A
10440
- }), x = ye({ ...A, ...Sn(s) });
10440
+ const B = E.data();
10441
+ b.set(_.collection, {
10442
+ ...b.get(_.collection) || {},
10443
+ [v]: B
10444
+ }), I = ye({ ...B, ...Sn(s) });
10441
10445
  }
10442
- x[N.name][t] && delete x[N.name][t], Array.isArray(x[`${N.name}_Array`]) && (x[`${N.name}_Array`] = x[`${N.name}_Array`].filter((O) => O !== t)), p.size === 1 && delete x[`${N.name}_Single`], y.set(w.collection, {
10443
- ...y.get(w.collection) || {},
10444
- [v]: x
10446
+ I[x.name][t] && delete I[x.name][t], Array.isArray(I[`${x.name}_Array`]) && (I[`${x.name}_Array`] = I[`${x.name}_Array`].filter((k) => k !== t)), p.size === 1 && delete I[`${x.name}_Single`], y.set(_.collection, {
10447
+ ...y.get(_.collection) || {},
10448
+ [v]: I
10445
10449
  });
10446
10450
  }
10447
10451
  }
10448
10452
  }
10449
10453
  }
10450
- for (const [w, b] of y.entries()) {
10451
- const N = o.collections[w], p = Je(w, o);
10452
- for (const [T, C] of Object.entries(b)) {
10453
- const { addedFields: v, removedFields: Z } = Wc(n, T, w, i, s, h);
10454
+ for (const [_, S] of y.entries()) {
10455
+ const x = o.collections[_], p = Je(_, o);
10456
+ for (const [R, A] of Object.entries(S)) {
10457
+ const { addedFields: v, removedFields: j } = Wc(n, R, _, i, s, h);
10454
10458
  if (c && u) {
10455
- for (const x of v) {
10456
- const g = W(N.fields, x.twoWay);
10457
- if (!rr(N, g, u)) {
10458
- gn(x, r, T);
10459
+ for (const I of v) {
10460
+ const g = V(x.fields, I.twoWay);
10461
+ if (!rr(x, g, u)) {
10462
+ gn(I, r, R);
10459
10463
  continue;
10460
10464
  }
10461
10465
  }
10462
- for (const x of Z) {
10463
- const g = W(N.fields, x.twoWay), O = ft(N, [g]);
10464
- if (!rr(N, g, u)) {
10466
+ for (const I of j) {
10467
+ const g = V(x.fields, I.twoWay), k = ft(x, [g]);
10468
+ if (!rr(x, g, u)) {
10465
10469
  ys(
10466
- x,
10470
+ I,
10467
10471
  r,
10468
10472
  // eslint-disable-next-line security/detect-object-injection
10469
- h?.[x.name]?.[T],
10470
- T,
10471
- O.size === 1
10473
+ h?.[I.name]?.[R],
10474
+ R,
10475
+ k.size === 1
10472
10476
  );
10473
10477
  continue;
10474
10478
  }
10475
10479
  }
10476
10480
  if (!it(
10477
10481
  "Update",
10478
- N,
10482
+ x,
10479
10483
  o,
10480
10484
  c,
10481
10485
  u,
10482
10486
  // eslint-disable-next-line security/detect-object-injection
10483
- k.get(w)?.[T]
10487
+ b.get(_)?.[R]
10484
10488
  )) {
10485
- for (const x of v)
10486
- gn(x, r, T);
10487
- for (const x of Z) {
10488
- const g = W(N.fields, x.twoWay), O = ft(N, [g]);
10489
+ for (const I of v)
10490
+ gn(I, r, R);
10491
+ for (const I of j) {
10492
+ const g = V(x.fields, I.twoWay), k = ft(x, [g]);
10489
10493
  ys(
10490
- x,
10494
+ I,
10491
10495
  r,
10492
10496
  // eslint-disable-next-line security/detect-object-injection
10493
- h?.[x.name]?.[T],
10494
- T,
10495
- O.size === 1
10497
+ h?.[I.name]?.[R],
10498
+ R,
10499
+ k.size === 1
10496
10500
  );
10497
10501
  }
10498
10502
  }
10499
- if (!it("Update", N, o, c, u, C)) {
10500
- for (const x of v)
10501
- gn(x, r, T);
10502
- for (const x of Z) {
10503
- const g = W(N.fields, x.twoWay), O = ft(N, [g]);
10503
+ if (!it("Update", x, o, c, u, A)) {
10504
+ for (const I of v)
10505
+ gn(I, r, R);
10506
+ for (const I of j) {
10507
+ const g = V(x.fields, I.twoWay), k = ft(x, [g]);
10504
10508
  ys(
10505
- x,
10509
+ I,
10506
10510
  r,
10507
10511
  // eslint-disable-next-line security/detect-object-injection
10508
- h?.[x.name]?.[T],
10509
- T,
10510
- O.size === 1
10512
+ h?.[I.name]?.[R],
10513
+ R,
10514
+ k.size === 1
10511
10515
  );
10512
10516
  }
10513
10517
  }
10514
10518
  }
10515
10519
  try {
10516
- await sn("update", C, N, p, ["update", C, {}, void 0, C], o);
10517
- } catch (x) {
10518
- throw new Error(`VALIDATION_ERROR: Two way relation update would invalidate record ${T} in ${w}: ${x.message}`);
10520
+ await sn("update", A, x, p, ["update", A, {}, void 0, A], o);
10521
+ } catch (I) {
10522
+ throw new Error(`VALIDATION_ERROR: Two way relation update would invalidate record ${R} in ${_}: ${I.message}`);
10519
10523
  }
10520
- for (const x of v) {
10521
- const g = W(N.fields, x.twoWay);
10522
- ["OneToOne", "OneToMany"].includes(g.type) && K(g) && g.enforceHierarchy && await ei(e, N, g, C, a, l, !0);
10524
+ for (const I of v) {
10525
+ const g = V(x.fields, I.twoWay);
10526
+ ["OneToOne", "OneToMany"].includes(g.type) && K(g) && g.enforceHierarchy && await ei(e, x, g, A, a, l, !0);
10523
10527
  }
10524
10528
  }
10525
10529
  }
@@ -10580,22 +10584,22 @@ ${i}`);
10580
10584
  if (s.collections?.[a]?.restrictEntities || s?.collections?.[a]?.recordOwner?.active || s?.collections?.[a]?.recordUser?.active || s?.collections?.[a]?.recordProperty?.active) {
10581
10585
  const f = i?.collections?.[a], d = [];
10582
10586
  if (l.individualEntities) {
10583
- const m = l.individualEntities, k = f?.individualEntities || [], y = i ? m.filter((w) => !k.includes(w)) : m;
10584
- for (const w of y) {
10587
+ const m = l.individualEntities, b = f?.individualEntities || [], y = i ? m.filter((_) => !b.includes(_)) : m;
10588
+ for (const _ of y) {
10585
10589
  if (o && o.size++, o && o.size > 500)
10586
10590
  throw new Error("VALIDATION_ERROR: The number of operations in the Firestore transaction has exceeded the limit of 500. This is likely due to a large number of unique field checks or entity restrictions (in permissions when dealing with user collections).");
10587
10591
  d.push(async () => {
10588
- if (!await gs(n, u, w, t, s))
10592
+ if (!await gs(n, u, _, t, s))
10589
10593
  throw new Error("PERMISSION_DENIED");
10590
10594
  });
10591
10595
  }
10592
10596
  }
10593
10597
  if (l.parentEntities) {
10594
- const m = c.entityRestrictions?.restrictions?.find((p) => p.type === "Parent" && p.roles.some((T) => T.role === e.Role));
10598
+ const m = c.entityRestrictions?.restrictions?.find((p) => p.type === "Parent" && p.roles.some((R) => R.role === e.Role));
10595
10599
  if (!m)
10596
10600
  throw new Error("PERMISSION_DENIED");
10597
- const k = W(u.fields, m.collectionField), y = r.collections[k.collection], w = l.parentEntities, b = f?.parentEntities || [], N = i ? w.filter((p) => !b.includes(p)) : w;
10598
- for (const p of N) {
10601
+ const b = V(u.fields, m.collectionField), y = r.collections[b.collection], _ = l.parentEntities, S = f?.parentEntities || [], x = i ? _.filter((p) => !S.includes(p)) : _;
10602
+ for (const p of x) {
10599
10603
  if (o && o.size++, o && o.size > 500)
10600
10604
  throw new Error("VALIDATION_ERROR: The number of operations in the Firestore transaction has exceeded the limit of 500. This is likely due to a large number of unique field checks or entity restrictions (in permissions when dealing with user collections).");
10601
10605
  d.push(async () => {
@@ -10605,13 +10609,13 @@ ${i}`);
10605
10609
  }
10606
10610
  }
10607
10611
  if (l.parentPropertyEntities) {
10608
- const m = c.entityRestrictions?.restrictions?.find((N) => N.type === "Parent_Property" && N.roles.some((p) => p.role === e.Role));
10612
+ const m = c.entityRestrictions?.restrictions?.find((x) => x.type === "Parent_Property" && x.roles.some((p) => p.role === e.Role));
10609
10613
  if (!m)
10610
10614
  throw new Error("PERMISSION_DENIED");
10611
- const k = W(u.fields, m.collectionField), y = r.collections[k.collection], w = l.parentPropertyEntities, b = f?.parentPropertyEntities || {};
10612
- for (const [N, p] of Object.entries(w)) {
10613
- const T = b[N] || [], C = i ? p.filter((v) => !T.includes(v)) : p;
10614
- for (const v of C) {
10615
+ const b = V(u.fields, m.collectionField), y = r.collections[b.collection], _ = l.parentPropertyEntities, S = f?.parentPropertyEntities || {};
10616
+ for (const [x, p] of Object.entries(_)) {
10617
+ const R = S[x] || [], A = i ? p.filter((v) => !R.includes(v)) : p;
10618
+ for (const v of A) {
10615
10619
  if (o && o.size++, o && o.size > 500)
10616
10620
  throw new Error("VALIDATION_ERROR: The number of operations in the Firestore transaction has exceeded the limit of 500. This is likely due to a large number of unique field checks or entity restrictions (in permissions when dealing with user collections).");
10617
10621
  d.push(async () => {
@@ -10632,121 +10636,121 @@ ${i}`);
10632
10636
  const u = n.at(-1), h = Object.keys(c.collections).includes(u), f = l.disabledCollections?.includes(u);
10633
10637
  if (!h || f)
10634
10638
  throw new Error("COLLECTION_NOT_FOUND");
10635
- const d = c.collections[u], { labels: m, fields: k, enableWriteLog: y, softDelete: w } = d, b = Je(m.collection, c), N = await ie(l.appName), p = ue(), T = gt(), v = (s ? await T.getUser(s) : void 0)?.customClaims?.role;
10636
- let Z;
10639
+ const d = c.collections[u], { labels: m, fields: b, enableWriteLog: y, softDelete: _ } = d, S = Je(m.collection, c), x = await ie(l.appName), p = ue(), R = gt(), v = (s ? await R.getUser(s) : void 0)?.customClaims?.role;
10640
+ let j;
10637
10641
  s && await er(n, d);
10638
- const x = De(p, n, a), g = o || x.doc().id;
10642
+ const I = De(p, n, a), g = o || I.doc().id;
10639
10643
  i = i || {}, i.collection = m.collection, e.id = g, Fo(e), tr(e);
10640
- const O = Ws("create", n, e, c, N, "Online", s || "System", lt.now(), me.serverTimestamp());
10641
- r?.createdAt && (O.Created_At = r.createdAt), r?.createdBy && (O.Created_By = r.createdBy);
10642
- const _ = ye(O);
10643
- w && (O[w.archivedField] = !1), Ve(e), y && await Mt("create", "started", O, a, n, g, d), await ae("preOperation", l, b, ["create", O, g, i]), await ae("preWrite", l, b, ["create", O, g, i]), Tn(d, O, c), Rn(d, O), await oa(O, d, b, v), Ve(O);
10644
+ const k = Ws("create", n, e, c, x, "Online", s || "System", lt.now(), me.serverTimestamp());
10645
+ r?.createdAt && (k.Created_At = r.createdAt), r?.createdBy && (k.Created_By = r.createdBy);
10646
+ const E = ye(k);
10647
+ _ && (k[_.archivedField] = !1), Ve(e), y && await Mt("create", "started", k, a, n, g, d), await ae("preOperation", l, S, ["create", k, g, i]), await ae("preWrite", l, S, ["create", k, g, i]), Tn(d, k, c), Rn(d, k), await oa(k, d, S, v), Ve(k);
10644
10648
  try {
10645
10649
  if (d.auth && t && !t.password)
10646
10650
  throw new Error("Password is required");
10647
- await Co("create", a, g, O, d, c), await sn("create", O, d, b, ["create", O, i], c);
10648
- } catch (P) {
10649
- throw new Error(`VALIDATION_ERROR: ${P.message}`);
10651
+ await Co("create", a, g, k, d, c), await sn("create", k, d, S, ["create", k, i], c);
10652
+ } catch (W) {
10653
+ throw new Error(`VALIDATION_ERROR: ${W.message}`);
10650
10654
  }
10651
- Ve(O), e.id = g, w && (O[w.archivedField] = !1), Tn(d, O, c), Rn(d, O);
10655
+ Ve(k), e.id = g, _ && (k[_.archivedField] = !1), Tn(d, k, c), Rn(d, k);
10652
10656
  try {
10653
- Lo("create", O, _), Vo("create", d, O), await sn("create", O, d, b, ["create", O, i], c);
10654
- } catch (P) {
10655
- throw new Error(`VALIDATION_ERROR: ${P.message}`);
10657
+ Lo("create", k, E), Vo("create", d, k), await sn("create", k, d, S, ["create", k, i], c);
10658
+ } catch (W) {
10659
+ throw new Error(`VALIDATION_ERROR: ${W.message}`);
10656
10660
  }
10657
10661
  if (s) {
10658
- const P = v;
10659
- if (!P)
10662
+ const W = v;
10663
+ if (!W)
10660
10664
  throw new Error("USER_ERROR");
10661
- if (!(b.custom?.serverAccess?.create !== void 0 ? await ie(b.custom.serverAccess.create, [P, O]) : !0))
10665
+ if (!(S.custom?.serverAccess?.create !== void 0 ? await ie(S.custom.serverAccess.create, [W, k]) : !0))
10662
10666
  throw new Error("PERMISSION_DENIED");
10663
- for (const Q of d.fields) {
10664
- if (!(Q.name in O))
10667
+ for (const J of d.fields) {
10668
+ if (!(J.name in k))
10665
10669
  continue;
10666
- const S = Ie(Q, b);
10667
- if (S?.custom?.serverAccess?.create !== void 0 && !await ie(S.custom.serverAccess.create, [P, O]))
10670
+ const O = Ie(J, S);
10671
+ if (O?.custom?.serverAccess?.create !== void 0 && !await ie(O.custom.serverAccess.create, [W, k]))
10668
10672
  throw new Error("PERMISSION_DENIED");
10669
10673
  }
10670
10674
  }
10671
- t && (t.permissions ||= {}, t.permissions.Role ||= O.Role, t.permissions.Enabled ||= O.Enabled);
10672
- const D = async (P, j) => {
10673
- const [Q, S, q, B] = await Promise.all([
10674
- P.get(p.collection("system_deployment").doc("latest_deploy")),
10675
- P.get(p.collection("system_deployment").doc("maintenance_mode")),
10676
- s ? P.get(p.collection("tenants").doc(a).collection("system_user_permissions").doc(s)) : Promise.resolve(Promise.resolve({})),
10675
+ t && (t.permissions ||= {}, t.permissions.Role ||= k.Role, t.permissions.Enabled ||= k.Enabled);
10676
+ const N = async (W, U) => {
10677
+ const [J, O, z, q] = await Promise.all([
10678
+ W.get(p.collection("system_deployment").doc("latest_deploy")),
10679
+ W.get(p.collection("system_deployment").doc("maintenance_mode")),
10680
+ s ? W.get(p.collection("tenants").doc(a).collection("system_user_permissions").doc(s)) : Promise.resolve(Promise.resolve({})),
10677
10681
  Ge()
10678
10682
  ]);
10679
- if (j && (j.size += 3), !Q.exists)
10683
+ if (U && (U.size += 3), !J.exists)
10680
10684
  throw new Error("VERSION_ERROR");
10681
- const re = Q.data();
10682
- if (re.force && O.Last_Write_At.valueOf() < re.time.valueOf())
10685
+ const re = J.data();
10686
+ if (re.force && k.Last_Write_At.valueOf() < re.time.valueOf())
10683
10687
  throw new Error("VERSION_ERROR");
10684
- if (!S.exists)
10688
+ if (!O.exists)
10685
10689
  throw new Error("MAINTENANCE_MODE");
10686
- if (S.data().active)
10690
+ if (O.data().active)
10687
10691
  throw new Error("MAINTENANCE_MODE");
10688
- if (c = B, s) {
10689
- if (!q?.exists)
10692
+ if (c = q, s) {
10693
+ if (!z?.exists)
10690
10694
  throw new Error("PERMISSION_DENIED");
10691
- if (Z = q.data(), !Z.Role)
10695
+ if (j = z.data(), !j.Role)
10692
10696
  throw new Error("USER_ERROR");
10693
- if (!Z.Enabled)
10697
+ if (!j.Enabled)
10694
10698
  throw new Error("PERMISSION_DENIED");
10695
10699
  }
10696
- const pe = k.filter((oe) => "unique" in oe && oe.unique).map(async (oe) => {
10697
- if (!s || !oe.access || oe.access.includes(Z.Role)) {
10700
+ const pe = b.filter((oe) => "unique" in oe && oe.unique).map(async (oe) => {
10701
+ if (!s || !oe.access || oe.access.includes(j.Role)) {
10698
10702
  if (!e[oe.name])
10699
10703
  return;
10700
- const Le = Ie(oe, b);
10704
+ const Le = Ie(oe, S);
10701
10705
  if (!(s && Le?.custom?.serverAccess?.read !== void 0 ? await ie(Le.custom.serverAccess.read, [
10702
- Z?.Role,
10703
- O
10706
+ j?.Role,
10707
+ k
10704
10708
  ]) : !0))
10705
10709
  throw new Error("PERMISSION_DENIED");
10706
10710
  const Jn = e[oe.name].toString().toLowerCase().replace(/\s/g, "---").replaceAll("/", "|||");
10707
10711
  if (Ks(Jn)) {
10708
- if (j && j.size++, j && j.size > 500)
10712
+ if (U && U.size++, U && U.size > 500)
10709
10713
  throw new Error("VALIDATION_ERROR: The number of operations in the Firestore transaction has exceeded the limit of 500. This is likely due to a large number of unique field checks.");
10710
- if ((await P.get(p.collection("tenants").doc(a).collection("system_unique").doc(m.collection).collection(`Unique-${m.collection}-${oe.name}`).doc(Jn)))?.exists)
10711
- throw new Error(`VALIDATION_ERROR: ${oe.name} "${O[oe.name]}" already exists`);
10714
+ if ((await W.get(p.collection("tenants").doc(a).collection("system_unique").doc(m.collection).collection(`Unique-${m.collection}-${oe.name}`).doc(Jn)))?.exists)
10715
+ throw new Error(`VALIDATION_ERROR: ${oe.name} "${k[oe.name]}" already exists`);
10712
10716
  } else
10713
- throw new Error(`VALIDATION_ERROR: ${oe.name} "${O[oe.name]}" is invalid`);
10717
+ throw new Error(`VALIDATION_ERROR: ${oe.name} "${k[oe.name]}" is invalid`);
10714
10718
  }
10715
10719
  });
10716
- await Promise.all(pe), ir(O, g, d, c, s, Z, t?.permissions), t?.permissions && s && Z && await Uo(P, t.permissions, s, Z, c), ir(O, g, d, c, s, Z, t?.permissions);
10720
+ await Promise.all(pe), ir(k, g, d, c, s, j, t?.permissions), t?.permissions && s && j && await Uo(W, t.permissions, s, j, c), ir(k, g, d, c, s, j, t?.permissions);
10717
10721
  };
10718
10722
  if (d.auth && t) {
10719
- await p.runTransaction(async (j) => {
10720
- await D(j);
10723
+ await p.runTransaction(async (U) => {
10724
+ await N(U);
10721
10725
  }, { maxAttempts: 10 });
10722
- const P = await Mo(
10726
+ const W = await Mo(
10723
10727
  a,
10724
10728
  g,
10725
10729
  l,
10726
10730
  m.collection,
10727
- O,
10731
+ k,
10728
10732
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
10729
10733
  t.permissions,
10730
10734
  t.password
10731
10735
  );
10732
- O.User_ID = P;
10736
+ k.User_ID = W;
10733
10737
  }
10734
10738
  try {
10735
- const P = { size: 1 };
10736
- await p.runTransaction(async (j) => {
10737
- await D(j, P), r?.noTwoWay || await Po("Create", a, g, O, O, d, c, j, P, s, Z);
10738
- const Q = Us(c);
10739
- Qs("create", j, n, g, O, c, d, r, Q, me.arrayUnion, me.arrayRemove, me.delete, (S) => p.collection("tenants").doc(a).collection("system_fields").doc(m.collection).collection(`${m.collection}-${S.name}`).doc(g), (S, q) => p.collection("tenants").doc(a).collection("system_unique").doc(m.collection).collection(`Unique-${m.collection}-${S.name}`).doc(q), (S) => p.collection("tenants").doc(a).collection("system_fields").doc(m.collection).collection(`${m.collection}-${S}`).doc(g), (S, q) => De(p, S, a).doc(q), (S, q, B) => p.collection("tenants").doc(a).collection("system_fields").doc(S.collection).collection(`${S.collection}-${q}`).doc(B), (S, q, B) => p.collection("tenants").doc(a).collection("system_fields").doc(S.collection).collection(`${S.collection}-${q.replaceAll(" ", "-")}`).doc(B), void 0, void 0, P), j.set(x.doc(g), O);
10739
+ const W = { size: 1 };
10740
+ await p.runTransaction(async (U) => {
10741
+ await N(U, W), r?.noTwoWay || await Po("Create", a, g, k, k, d, c, U, W, s, j);
10742
+ const J = Us(c);
10743
+ Qs("create", U, n, g, k, c, d, r, J, me.arrayUnion, me.arrayRemove, me.delete, (O) => p.collection("tenants").doc(a).collection("system_fields").doc(m.collection).collection(`${m.collection}-${O.name}`).doc(g), (O, z) => p.collection("tenants").doc(a).collection("system_unique").doc(m.collection).collection(`Unique-${m.collection}-${O.name}`).doc(z), (O) => p.collection("tenants").doc(a).collection("system_fields").doc(m.collection).collection(`${m.collection}-${O}`).doc(g), (O, z) => De(p, O, a).doc(z), (O, z, q) => p.collection("tenants").doc(a).collection("system_fields").doc(O.collection).collection(`${O.collection}-${z}`).doc(q), (O, z, q) => p.collection("tenants").doc(a).collection("system_fields").doc(O.collection).collection(`${O.collection}-${z.replaceAll(" ", "-")}`).doc(q), void 0, void 0, W), U.set(I.doc(g), k);
10740
10744
  }, { maxAttempts: 10 });
10741
- } catch (P) {
10742
- const Q = await ae("postWriteError", l, b, ["create", O, g, i, P]);
10743
- if (y && (await new Promise((S) => {
10744
- setTimeout(S, 250);
10745
- }), await Mt("create", Q?.resolved ? "success" : "failed", O, a, n, g, d, Q?.resolved ? void 0 : P)), !Q?.resolved)
10746
- throw d.auth && t && await un(O), P;
10747
- }
10748
- const R = ["create", O, g, i], F = [...R];
10749
- return await ae("postWrite", l, b, R), await ae("postOperation", l, b, F), { id: g, ...O };
10745
+ } catch (W) {
10746
+ const J = await ae("postWriteError", l, S, ["create", k, g, i, W]);
10747
+ if (y && (await new Promise((O) => {
10748
+ setTimeout(O, 250);
10749
+ }), await Mt("create", J?.resolved ? "success" : "failed", k, a, n, g, d, J?.resolved ? void 0 : W)), !J?.resolved)
10750
+ throw d.auth && t && await un(k), W;
10751
+ }
10752
+ const T = ["create", k, g, i], C = [...T];
10753
+ return await ae("postWrite", l, S, T), await ae("postOperation", l, S, C), { id: g, ...k };
10750
10754
  }, Qt = async (n, e, t, s) => {
10751
10755
  const r = Ye(), i = gt(), o = ue(), a = e.customClaims || {};
10752
10756
  let l = !1;
@@ -10783,14 +10787,14 @@ ${i}`);
10783
10787
  throw new Error(`ROLLBACK_FAILED: ${s}`);
10784
10788
  }, zc = async (n, e, t, s, r, i, o, a, l, c, u) => {
10785
10789
  const h = gt(), f = ue(), d = a?.customClaims || {}, m = "USER_ERROR";
10786
- let k = "";
10790
+ let b = "";
10787
10791
  if (n === "create") {
10788
10792
  if (!u)
10789
10793
  throw new Error("VALIDATION_ERROR: Password is required");
10790
10794
  if (!l)
10791
10795
  throw new Error("VALIDATION_ERROR: Permissions are required");
10792
10796
  try {
10793
- k = await Mo(e, t, s, r, i, l, u);
10797
+ b = await Mo(e, t, s, r, i, l, u);
10794
10798
  } catch (y) {
10795
10799
  throw new Error(y.message);
10796
10800
  }
@@ -10825,22 +10829,22 @@ ${i}`);
10825
10829
  throw await Qt(o.User_ID, a, c, m), new Error(m);
10826
10830
  }
10827
10831
  if (o.Email !== i.Email) {
10828
- const w = s.auth.enableMultiFactorAuth;
10829
- if (w === !0 || typeof w == "object" && w.includes(i.Role)) {
10830
- let b = await h.generateEmailVerificationLink(i.Email).catch(() => {
10832
+ const _ = s.auth.enableMultiFactorAuth;
10833
+ if (_ === !0 || typeof _ == "object" && _.includes(i.Role)) {
10834
+ let S = await h.generateEmailVerificationLink(i.Email).catch(() => {
10831
10835
  throw new Error("Error generating email verification link");
10832
10836
  });
10833
- if (b.includes("apiKey=&")) {
10834
- const N = JSON.parse(process.env.STOKER_FB_WEB_APP_CONFIG);
10835
- b = b.replace("apiKey=&", `apiKey=${N.apiKey}&`);
10837
+ if (S.includes("apiKey=&")) {
10838
+ const x = JSON.parse(process.env.STOKER_FB_WEB_APP_CONFIG);
10839
+ S = S.replace("apiKey=&", `apiKey=${x.apiKey}&`);
10836
10840
  }
10837
- if (b) {
10838
- const N = `https://${h.app.options.projectId}.firebaseapp.com/__/auth/action${b}`, p = await ie(s.appName), T = s?.mail?.emailVerification && s.mail.emailVerification(N, p);
10841
+ if (S) {
10842
+ const x = `https://${h.app.options.projectId}.firebaseapp.com/__/auth/action${S}`, p = await ie(s.appName), R = s?.mail?.emailVerification && s.mail.emailVerification(x, p);
10839
10843
  try {
10840
- await $o(i.Email, T?.subject || "Please verify your email address", void 0, T?.html || `Please verify your email address by clicking the link:
10844
+ await $o(i.Email, R?.subject || "Please verify your email address", void 0, R?.html || `Please verify your email address by clicking the link:
10841
10845
  </br>
10842
10846
  </br>
10843
- <a href="${N}">${N}</a>`);
10847
+ <a href="${x}">${x}</a>`);
10844
10848
  } catch {
10845
10849
  throw await Qt(o.User_ID, a, c, m), new Error(m);
10846
10850
  }
@@ -10853,8 +10857,8 @@ ${i}`);
10853
10857
  } catch (y) {
10854
10858
  throw new Error(y.message);
10855
10859
  }
10856
- if (k)
10857
- return k;
10860
+ if (b)
10861
+ return b;
10858
10862
  }, qc = async (n, e, t) => {
10859
10863
  const s = Ye(), r = ue(), i = [e];
10860
10864
  t && t.trim() !== "" && i.push(t), i.sort();
@@ -10884,25 +10888,25 @@ ${i}`);
10884
10888
  const u = n.at(-1), h = Object.keys(c.collections).includes(u), f = l.disabledCollections?.includes(u);
10885
10889
  if (!h || f)
10886
10890
  throw new Error("COLLECTION_NOT_FOUND");
10887
- const d = c.collections[u], { labels: m, fields: k, enableWriteLog: y } = d, w = Je(m.collection, c), b = await ie(l.appName), N = gt(), p = ue();
10888
- let T;
10891
+ const d = c.collections[u], { labels: m, fields: b, enableWriteLog: y } = d, _ = Je(m.collection, c), S = await ie(l.appName), x = gt(), p = ue();
10892
+ let R;
10889
10893
  r && await er(n, d);
10890
- const C = De(p, n, a);
10894
+ const A = De(p, n, a);
10891
10895
  o = o || {}, o.collection = m.collection;
10892
10896
  let v = await at(n, e, {
10893
10897
  user: r,
10894
10898
  noComputedFields: !0,
10895
10899
  noEmbeddingFields: !0
10896
10900
  });
10897
- for (const S of k)
10898
- S.type === "Computed" && delete t[S.name];
10901
+ for (const O of b)
10902
+ O.type === "Computed" && delete t[O.name];
10899
10903
  if (c = {
10900
10904
  ...c,
10901
- collections: Object.fromEntries(Object.entries(c.collections).map(([S, q]) => [
10902
- S,
10905
+ collections: Object.fromEntries(Object.entries(c.collections).map(([O, z]) => [
10906
+ O,
10903
10907
  {
10904
- ...q,
10905
- fields: q.fields.filter((B) => B.type !== "Computed")
10908
+ ...z,
10909
+ fields: z.fields.filter((q) => q.type !== "Computed")
10906
10910
  }
10907
10911
  ]))
10908
10912
  }, s && !s.operation)
@@ -10911,58 +10915,58 @@ ${i}`);
10911
10915
  throw new Error("VALIDATION_ERROR: User operations are only permitted for auth collections");
10912
10916
  if (s?.operation === "delete" && s.permissions)
10913
10917
  throw new Error("VALIDATION_ERROR: Permissions are not allowed for delete operations");
10914
- const Z = d.auth && s?.operation === "create", x = d.auth && s?.operation === "delete", g = d.auth && !Z && !x && (s?.operation === "update" || t.Role || t.Enabled !== void 0 || t.Name || t.Email || t.Photo_URL), O = (S) => S.User_ID && (d.auth && !Z && !x && s?.operation === "update" || t.Role && t.Role !== S.Role || t.Enabled !== void 0 && t.Enabled !== S.Enabled || t.Name && t.Name !== S.Name || t.Email && t.Email !== S.Email || t.Photo_URL && t.Photo_URL !== S.Photo_URL);
10918
+ const j = d.auth && s?.operation === "create", I = d.auth && s?.operation === "delete", g = d.auth && !j && !I && (s?.operation === "update" || t.Role || t.Enabled !== void 0 || t.Name || t.Email || t.Photo_URL), k = (O) => O.User_ID && (d.auth && !j && !I && s?.operation === "update" || t.Role && t.Role !== O.Role || t.Enabled !== void 0 && t.Enabled !== O.Enabled || t.Name && t.Name !== O.Name || t.Email && t.Email !== O.Email || t.Photo_URL && t.Photo_URL !== O.Photo_URL);
10915
10919
  delete t.id, Fo(t), tr(t);
10916
- const _ = Ws("update", n, t, c, b, "Online", r || "System", lt.now(), me.serverTimestamp()), A = ye(_);
10917
- for (const S of k)
10918
- !K(S) && Me(_[S.name]) && S.nullable && (_[S.name] = null);
10919
- Ve(_), Ve(v), y && await Mt("update", "started", _, a, n, e, d, void 0, v);
10920
- const E = [
10920
+ const E = Ws("update", n, t, c, S, "Online", r || "System", lt.now(), me.serverTimestamp()), B = ye(E);
10921
+ for (const O of b)
10922
+ !K(O) && Me(E[O.name]) && O.nullable && (E[O.name] = null);
10923
+ Ve(E), Ve(v), y && await Mt("update", "started", E, a, n, e, d, void 0, v);
10924
+ const w = [
10921
10925
  "update",
10922
- _,
10926
+ E,
10923
10927
  e,
10924
10928
  o,
10925
10929
  void 0,
10926
10930
  ye(v)
10927
10931
  ];
10928
- await ae("preOperation", l, w, E);
10929
- const D = ["update", _, e, o, void 0, ye(v)];
10930
- await ae("preWrite", l, w, D), Tn(d, _, c), Rn(d, _), Ve(_);
10932
+ await ae("preOperation", l, _, w);
10933
+ const N = ["update", E, e, o, void 0, ye(v)];
10934
+ await ae("preWrite", l, _, N), Tn(d, E, c), Rn(d, E), Ve(E);
10931
10935
  try {
10932
- if (Z && !s.password)
10936
+ if (j && !s.password)
10933
10937
  throw new Error("Password is required");
10934
- const S = { ...v, ..._ };
10935
- await Co("update", a, e, S, d, c), nt(S), await sn("update", S, d, w, ["update", _, o, void 0, ye(v)], c);
10936
- } catch (S) {
10937
- throw new Error(`VALIDATION_ERROR: ${S.message}`);
10938
- }
10939
- Ve(_), delete t.id, Tn(d, _, c), Rn(d, _);
10940
- for (const S of k)
10941
- !K(S) && Me(_[S.name]) && S.nullable && (_[S.name] = null);
10938
+ const O = { ...v, ...E };
10939
+ await Co("update", a, e, O, d, c), nt(O), await sn("update", O, d, _, ["update", E, o, void 0, ye(v)], c);
10940
+ } catch (O) {
10941
+ throw new Error(`VALIDATION_ERROR: ${O.message}`);
10942
+ }
10943
+ Ve(E), delete t.id, Tn(d, E, c), Rn(d, E);
10944
+ for (const O of b)
10945
+ !K(O) && Me(E[O.name]) && O.nullable && (E[O.name] = null);
10942
10946
  try {
10943
- const S = { ...v, ..._ };
10944
- nt(S), Vo("update", d, _, v), Lo("update", _, A), await sn("update", S, d, w, ["update", _, o, void 0, v], c);
10945
- } catch (S) {
10946
- throw new Error(`VALIDATION_ERROR: ${S.message}`);
10947
+ const O = { ...v, ...E };
10948
+ nt(O), Vo("update", d, E, v), Lo("update", E, B), await sn("update", O, d, _, ["update", E, o, void 0, v], c);
10949
+ } catch (O) {
10950
+ throw new Error(`VALIDATION_ERROR: ${O.message}`);
10947
10951
  }
10948
- let R;
10952
+ let T;
10949
10953
  s && (s.permissions ||= {});
10950
- const F = async (S, q, B) => {
10954
+ const C = async (O, z, q) => {
10951
10955
  const [re, Qe, Wt, pe, oe] = await Promise.all([
10952
- S.get(p.collection("system_deployment").doc("latest_deploy")),
10953
- S.get(p.collection("system_deployment").doc("maintenance_mode")),
10956
+ O.get(p.collection("system_deployment").doc("latest_deploy")),
10957
+ O.get(p.collection("system_deployment").doc("maintenance_mode")),
10954
10958
  at(n, e, {
10955
10959
  user: r,
10956
- providedTransaction: S,
10960
+ providedTransaction: O,
10957
10961
  noComputedFields: !0
10958
10962
  }),
10959
- r ? S.get(p.collection("tenants").doc(a).collection("system_user_permissions").doc(r)) : Promise.resolve(Promise.resolve({})),
10963
+ r ? O.get(p.collection("tenants").doc(a).collection("system_user_permissions").doc(r)) : Promise.resolve(Promise.resolve({})),
10960
10964
  Ge()
10961
10965
  ]);
10962
- if (B && (B.size += 3), !re.exists)
10966
+ if (q && (q.size += 3), !re.exists)
10963
10967
  throw new Error("VERSION_ERROR");
10964
10968
  const Le = re.data();
10965
- if (Le.force && _.Last_Write_At.valueOf() < Le.time.valueOf())
10969
+ if (Le.force && E.Last_Write_At.valueOf() < Le.time.valueOf())
10966
10970
  throw new Error("VERSION_ERROR");
10967
10971
  if (!Qe.exists)
10968
10972
  throw new Error("MAINTENANCE_MODE");
@@ -10973,52 +10977,52 @@ ${i}`);
10973
10977
  if (v = Wt, c = oe, r) {
10974
10978
  if (!pe?.exists)
10975
10979
  throw new Error("PERMISSION_DENIED");
10976
- if (T = pe.data(), !T.Role)
10980
+ if (R = pe.data(), !R.Role)
10977
10981
  throw new Error("USER_ERROR");
10978
- if (!T.Enabled)
10982
+ if (!R.Enabled)
10979
10983
  throw new Error("PERMISSION_DENIED");
10980
10984
  }
10981
- if (B && (B.size += No(a, n, e, c, T).length), Z && v.User_ID || x && !v.User_ID)
10985
+ if (q && (q.size += No(a, n, e, c, R).length), j && v.User_ID || I && !v.User_ID)
10982
10986
  throw new Error("USER_ERROR");
10983
- if (O(v)) {
10984
- const de = await S.get(p.collection("tenants").doc(a).collection("system_user_permissions").doc(v.User_ID));
10985
- if (B && B.size++, !de?.exists)
10987
+ if (k(v)) {
10988
+ const de = await O.get(p.collection("tenants").doc(a).collection("system_user_permissions").doc(v.User_ID));
10989
+ if (q && q.size++, !de?.exists)
10986
10990
  throw new Error("PERMISSION_DENIED");
10987
- if (R = de.data(), s?.permissions) {
10988
- if (s.permissions.Role ||= _.Role || v.Role, s.permissions.Enabled ??= _.Enabled ?? v.Enabled, Me(s.permissions.Role))
10991
+ if (T = de.data(), s?.permissions) {
10992
+ if (s.permissions.Role ||= E.Role || v.Role, s.permissions.Enabled ??= E.Enabled ?? v.Enabled, Me(s.permissions.Role))
10989
10993
  throw new Error("VALIDATION_ERROR: Role field is required");
10990
10994
  if (Me(s.permissions.Enabled))
10991
10995
  throw new Error("VALIDATION_ERROR: Enabled field is required");
10992
10996
  }
10993
10997
  }
10994
- const nr = k.filter((de) => "unique" in de && de.unique).map(async (de) => {
10995
- if (!r || !de.access || de.access.includes(T.Role)) {
10996
- if (_[de.name] === void 0 || Me(_[de.name]))
10998
+ const nr = b.filter((de) => "unique" in de && de.unique).map(async (de) => {
10999
+ if (!r || !de.access || de.access.includes(R.Role)) {
11000
+ if (E[de.name] === void 0 || Me(E[de.name]))
10997
11001
  return;
10998
- const jt = Ie(de, w), sr = { ...v, ..._ };
11002
+ const jt = Ie(de, _), sr = { ...v, ...E };
10999
11003
  if (!(r && jt?.custom?.serverAccess?.read !== void 0 ? await ie(jt.custom.serverAccess.read, [
11000
- T?.Role,
11004
+ R?.Role,
11001
11005
  sr
11002
11006
  ]) : !0))
11003
11007
  throw new Error("PERMISSION_DENIED");
11004
- const Zt = _[de.name].toString().toLowerCase().replace(/\s/g, "---").replaceAll("/", "|||");
11008
+ const Zt = E[de.name].toString().toLowerCase().replace(/\s/g, "---").replaceAll("/", "|||");
11005
11009
  if (Ks(Zt)) {
11006
- if (B && B.size++, B && B.size > 500)
11010
+ if (q && q.size++, q && q.size > 500)
11007
11011
  throw new Error("VALIDATION_ERROR: The number of operations in the Firestore transaction has exceeded the limit of 500. This is likely due to a large number of unique field checks.");
11008
- const Kn = await S.get(p.collection("tenants").doc(a).collection("system_unique").doc(m.collection).collection(`Unique-${m.collection}-${de.name}`).doc(Zt));
11012
+ const Kn = await O.get(p.collection("tenants").doc(a).collection("system_unique").doc(m.collection).collection(`Unique-${m.collection}-${de.name}`).doc(Zt));
11009
11013
  if (Kn.exists && Kn.data().id !== e)
11010
- throw new Error(`VALIDATION_ERROR: ${de.name} "${_[de.name]}" already exists`);
11014
+ throw new Error(`VALIDATION_ERROR: ${de.name} "${E[de.name]}" already exists`);
11011
11015
  } else
11012
- throw new Error(`VALIDATION_ERROR: ${de.name} "${_[de.name]}" is invalid`);
11016
+ throw new Error(`VALIDATION_ERROR: ${de.name} "${E[de.name]}" is invalid`);
11013
11017
  }
11014
11018
  });
11015
- if (await Promise.all(nr), r && T?.Role) {
11016
- const de = T.Role, jt = { ...v, ..._ };
11017
- if (!(w.custom?.serverAccess?.update !== void 0 ? await ie(w.custom.serverAccess.update, [de, jt, v]) : !0))
11019
+ if (await Promise.all(nr), r && R?.Role) {
11020
+ const de = R.Role, jt = { ...v, ...E };
11021
+ if (!(_.custom?.serverAccess?.update !== void 0 ? await ie(_.custom.serverAccess.update, [de, jt, v]) : !0))
11018
11022
  throw new Error("PERMISSION_DENIED");
11019
11023
  for (const Qn of d.fields) {
11020
- const Zt = Ie(Qn, w);
11021
- if (Object.prototype.hasOwnProperty.call(_, Qn.name) && Zt?.custom?.serverAccess?.update !== void 0 && !await ie(Zt.custom.serverAccess.update, [
11024
+ const Zt = Ie(Qn, _);
11025
+ if (Object.prototype.hasOwnProperty.call(E, Qn.name) && Zt?.custom?.serverAccess?.update !== void 0 && !await ie(Zt.custom.serverAccess.update, [
11022
11026
  de,
11023
11027
  jt,
11024
11028
  v
@@ -11026,63 +11030,63 @@ ${i}`);
11026
11030
  throw new Error("PERMISSION_DENIED");
11027
11031
  }
11028
11032
  }
11029
- or(_, v, e, d, c, r, T, s?.operation ? s.operation : g ? "update" : void 0, s?.permissions, R), s?.permissions && r && T && await Uo(S, s.permissions, r, T, c, R, B), or(_, v, e, d, c, r, T, s?.operation ? s.operation : g ? "update" : void 0, s?.permissions, R), q && (Z || O(v) || x) && await qc(S, e, v.User_ID);
11033
+ or(E, v, e, d, c, r, R, s?.operation ? s.operation : g ? "update" : void 0, s?.permissions, T), s?.permissions && r && R && await Uo(O, s.permissions, r, R, c, T, q), or(E, v, e, d, c, r, R, s?.operation ? s.operation : g ? "update" : void 0, s?.permissions, T), z && (j || k(v) || I) && await qc(O, e, v.User_ID);
11030
11034
  };
11031
- (Z || g || x) && await p.runTransaction(async (S) => {
11032
- await F(S, !0);
11035
+ (j || g || I) && await p.runTransaction(async (O) => {
11036
+ await C(O, !0);
11033
11037
  }, { maxAttempts: 10 });
11034
11038
  try {
11035
- let S;
11036
- if (Z || O(v) || x) {
11037
- if (O(v)) {
11038
- S = await N.getUser(v.User_ID);
11039
- const re = S.customClaims;
11039
+ let O;
11040
+ if (j || k(v) || I) {
11041
+ if (k(v)) {
11042
+ O = await x.getUser(v.User_ID);
11043
+ const re = O.customClaims;
11040
11044
  if (!(re && re.role && re.collection && re.doc))
11041
11045
  throw new Error("USER_ERROR");
11042
11046
  }
11043
- const q = { ...v, ..._ };
11044
- nt(q);
11045
- const B = await zc(s?.operation || "update", a, e, l, m.collection, q, v, S, s?.permissions, R, s?.password);
11046
- Z && (_.User_ID = B), x && (_.User_ID = me.delete());
11047
+ const z = { ...v, ...E };
11048
+ nt(z);
11049
+ const q = await zc(s?.operation || "update", a, e, l, m.collection, z, v, O, s?.permissions, T, s?.password);
11050
+ j && (E.User_ID = q), I && (E.User_ID = me.delete());
11047
11051
  }
11048
11052
  try {
11049
- const q = { size: 1 };
11050
- await p.runTransaction(async (B) => {
11051
- const re = { ...v, ..._ };
11052
- await F(B, !1, q);
11053
+ const z = { size: 1 };
11054
+ await p.runTransaction(async (q) => {
11055
+ const re = { ...v, ...E };
11056
+ await C(q, !1, z);
11053
11057
  let Qe;
11054
- i?.noTwoWay || (Qe = await Po("Update", a, e, re, _, d, c, B, q, r, T, v));
11058
+ i?.noTwoWay || (Qe = await Po("Update", a, e, re, E, d, c, q, z, r, R, v));
11055
11059
  const Wt = Us(c);
11056
- Qs("update", B, n, e, _, c, d, i, Wt, me.arrayUnion, me.arrayRemove, me.delete, (pe) => p.collection("tenants").doc(a).collection("system_fields").doc(m.collection).collection(`${m.collection}-${pe.name}`).doc(e), (pe, oe) => p.collection("tenants").doc(a).collection("system_unique").doc(m.collection).collection(`Unique-${m.collection}-${pe.name}`).doc(oe), (pe) => p.collection("tenants").doc(a).collection("system_fields").doc(m.collection).collection(`${m.collection}-${pe}`).doc(e), (pe, oe) => De(p, pe, a).doc(oe), (pe, oe, Le) => p.collection("tenants").doc(a).collection("system_fields").doc(pe.collection).collection(`${pe.collection}-${oe}`).doc(Le), (pe, oe, Le) => p.collection("tenants").doc(a).collection("system_fields").doc(pe.collection).collection(`${pe.collection}-${oe.replaceAll(" ", "-")}`).doc(Le), v, Qe, q), B.update(C.doc(e), _);
11060
+ Qs("update", q, n, e, E, c, d, i, Wt, me.arrayUnion, me.arrayRemove, me.delete, (pe) => p.collection("tenants").doc(a).collection("system_fields").doc(m.collection).collection(`${m.collection}-${pe.name}`).doc(e), (pe, oe) => p.collection("tenants").doc(a).collection("system_unique").doc(m.collection).collection(`Unique-${m.collection}-${pe.name}`).doc(oe), (pe) => p.collection("tenants").doc(a).collection("system_fields").doc(m.collection).collection(`${m.collection}-${pe}`).doc(e), (pe, oe) => De(p, pe, a).doc(oe), (pe, oe, Le) => p.collection("tenants").doc(a).collection("system_fields").doc(pe.collection).collection(`${pe.collection}-${oe}`).doc(Le), (pe, oe, Le) => p.collection("tenants").doc(a).collection("system_fields").doc(pe.collection).collection(`${pe.collection}-${oe.replaceAll(" ", "-")}`).doc(Le), v, Qe, z), q.update(A.doc(e), E);
11057
11061
  }, { maxAttempts: 10 });
11058
- } catch (q) {
11059
- const B = [
11062
+ } catch (z) {
11063
+ const q = [
11060
11064
  "update",
11061
- _,
11065
+ E,
11062
11066
  e,
11063
11067
  o,
11064
- q,
11068
+ z,
11065
11069
  void 0,
11066
11070
  void 0,
11067
11071
  ye(v)
11068
- ], re = await ae("postWriteError", l, w, B);
11072
+ ], re = await ae("postWriteError", l, _, q);
11069
11073
  if (y && (await new Promise((Qe) => {
11070
11074
  setTimeout(Qe, 250);
11071
- }), await Mt("update", re?.resolved ? "success" : "failed", _, a, n, e, d, re?.resolved ? void 0 : q, v)), !re?.resolved)
11072
- throw Z && await un(v), O(v) && await Qt(v.User_ID, S, R, "USER_ERROR"), x && await p.collection("tenants").doc(a).collection(m.collection).doc(e).update({ User_ID: me.delete() }), q;
11075
+ }), await Mt("update", re?.resolved ? "success" : "failed", E, a, n, e, d, re?.resolved ? void 0 : z, v)), !re?.resolved)
11076
+ throw j && await un(v), k(v) && await Qt(v.User_ID, O, T, "USER_ERROR"), I && await p.collection("tenants").doc(a).collection(m.collection).doc(e).update({ User_ID: me.delete() }), z;
11073
11077
  }
11074
- (Z || O(v) || x) && await Qr(ti, [e, v.User_ID]).catch(() => {
11078
+ (j || k(v) || I) && await Qr(ti, [e, v.User_ID]).catch(() => {
11075
11079
  throw new Error("USER_ERROR");
11076
11080
  });
11077
- } catch (S) {
11078
- throw (Z || O(v) || x) && await Qr(ti, [e, v.User_ID]).catch(() => {
11081
+ } catch (O) {
11082
+ throw (j || k(v) || I) && await Qr(ti, [e, v.User_ID]).catch(() => {
11079
11083
  throw new Error("USER_ERROR");
11080
- }), S;
11084
+ }), O;
11081
11085
  }
11082
- const M = ["update", _, e, o, void 0, ye(v)], P = [...M];
11083
- await ae("postWrite", l, w, M), await ae("postOperation", l, w, P);
11084
- const j = { ...v, ..._ };
11085
- return nt(j), { id: e, ...j };
11086
+ const F = ["update", E, e, o, void 0, ye(v)], W = [...F];
11087
+ await ae("postWrite", l, _, F), await ae("postOperation", l, _, W);
11088
+ const U = { ...v, ...E };
11089
+ return nt(U), { id: e, ...U };
11086
11090
  }, gu = async (n, e, t, s, r) => {
11087
11091
  const i = Ye(), o = Ut();
11088
11092
  let a = await Ge();
@@ -11091,64 +11095,64 @@ ${i}`);
11091
11095
  const l = n.at(-1), c = Object.keys(a.collections).includes(l), u = o.disabledCollections?.includes(l);
11092
11096
  if (!c || u)
11093
11097
  throw new Error("COLLECTION_NOT_FOUND");
11094
- const h = a.collections[l], { labels: f, auth: d, enableWriteLog: m, softDelete: k } = h, y = Je(f.collection, a), w = await ie(o.appName);
11095
- if (k && !d && !s?.force)
11096
- return await Bc(n, e, { [k.archivedField]: !0, [k.timestampField]: me.serverTimestamp() }, void 0, t);
11097
- const b = ue();
11098
- let N;
11098
+ const h = a.collections[l], { labels: f, auth: d, enableWriteLog: m, softDelete: b } = h, y = Je(f.collection, a), _ = await ie(o.appName);
11099
+ if (b && !d && !s?.force)
11100
+ return await Bc(n, e, { [b.archivedField]: !0, [b.timestampField]: me.serverTimestamp() }, void 0, t);
11101
+ const S = ue();
11102
+ let x;
11099
11103
  t && await er(n, h);
11100
- const p = De(b, n, i);
11104
+ const p = De(S, n, i);
11101
11105
  r = r || {}, r.collection = f.collection;
11102
- const T = await at(n, e, { user: t });
11103
- let C = Ws("delete", n, T, a, w, "Online", t || "System", lt.now(), me.serverTimestamp());
11104
- const v = Sn(C);
11105
- Ve(C), m && await Mt("delete", "started", C, i, n, e, h), await ae("preOperation", o, y, ["delete", C, e, r]), await ae("preWrite", o, y, ["delete", C, e, r]), Ve(C);
11106
- const g = async (E) => {
11107
- const [D, R, F, M] = await Promise.all([
11108
- E.get(b.collection("system_deployment").doc("maintenance_mode")),
11109
- at([f.collection], e, { user: t, providedTransaction: E }),
11110
- t ? E.get(b.collection("tenants").doc(i).collection("system_user_permissions").doc(t)) : Promise.resolve(Promise.resolve({})),
11106
+ const R = await at(n, e, { user: t });
11107
+ let A = Ws("delete", n, R, a, _, "Online", t || "System", lt.now(), me.serverTimestamp());
11108
+ const v = Sn(A);
11109
+ Ve(A), m && await Mt("delete", "started", A, i, n, e, h), await ae("preOperation", o, y, ["delete", A, e, r]), await ae("preWrite", o, y, ["delete", A, e, r]), Ve(A);
11110
+ const g = async (w) => {
11111
+ const [N, T, C, F] = await Promise.all([
11112
+ w.get(S.collection("system_deployment").doc("maintenance_mode")),
11113
+ at([f.collection], e, { user: t, providedTransaction: w }),
11114
+ t ? w.get(S.collection("tenants").doc(i).collection("system_user_permissions").doc(t)) : Promise.resolve(Promise.resolve({})),
11111
11115
  Ge()
11112
11116
  ]);
11113
- if (!D.exists)
11117
+ if (!N.exists)
11114
11118
  throw new Error("MAINTENANCE_MODE");
11115
- if (D.data().active)
11119
+ if (N.data().active)
11116
11120
  throw new Error("MAINTENANCE_MODE");
11117
- if (!R)
11121
+ if (!T)
11118
11122
  throw new Error("NOT_FOUND");
11119
- if (C = { ...R, ...v }, a = M, t) {
11120
- if (!F?.exists)
11123
+ if (A = { ...T, ...v }, a = F, t) {
11124
+ if (!C?.exists)
11121
11125
  throw new Error("PERMISSION_DENIED");
11122
- if (N = F.data(), !N.Role)
11126
+ if (x = C.data(), !x.Role)
11123
11127
  throw new Error("USER_ERROR");
11124
- if (!N.Enabled)
11128
+ if (!x.Enabled)
11125
11129
  throw new Error("PERMISSION_DENIED");
11126
- Qo(C, e, h, a, t, N);
11130
+ Qo(A, e, h, a, t, x);
11127
11131
  }
11128
- if (t && N?.Role) {
11129
- const j = N.Role;
11130
- if (!(y.custom?.serverAccess?.delete !== void 0 ? await ie(y.custom.serverAccess.delete, [j, C]) : !0))
11132
+ if (t && x?.Role) {
11133
+ const U = x.Role;
11134
+ if (!(y.custom?.serverAccess?.delete !== void 0 ? await ie(y.custom.serverAccess.delete, [U, A]) : !0))
11131
11135
  throw new Error("PERMISSION_DENIED");
11132
11136
  }
11133
11137
  };
11134
- h.auth && (await b.runTransaction(async (E) => {
11135
- await g(E);
11136
- }, { maxAttempts: 10 }), C.User_ID && await un(C));
11138
+ h.auth && (await S.runTransaction(async (w) => {
11139
+ await g(w);
11140
+ }, { maxAttempts: 10 }), A.User_ID && await un(A));
11137
11141
  try {
11138
- await b.runTransaction(async (E) => {
11139
- await g(E);
11140
- const D = Us(a);
11141
- Qs("delete", E, n, e, C, a, h, s, D, me.arrayUnion, me.arrayRemove, me.delete, (R) => b.collection("tenants").doc(i).collection("system_fields").doc(f.collection).collection(`${f.collection}-${R.name}`).doc(e), (R, F) => b.collection("tenants").doc(i).collection("system_unique").doc(f.collection).collection(`Unique-${f.collection}-${R.name}`).doc(F), (R) => b.collection("tenants").doc(i).collection("system_fields").doc(f.collection).collection(`${f.collection}-${R}`).doc(e), (R, F) => De(b, R, i).doc(F), (R, F, M) => b.collection("tenants").doc(i).collection("system_fields").doc(R.collection).collection(`${R.collection}-${F}`).doc(M), (R, F, M) => b.collection("tenants").doc(i).collection("system_fields").doc(R.collection).collection(`${R.collection}-${F.replaceAll(" ", "-")}`).doc(M)), E.delete(p.doc(e));
11142
+ await S.runTransaction(async (w) => {
11143
+ await g(w);
11144
+ const N = Us(a);
11145
+ Qs("delete", w, n, e, A, a, h, s, N, me.arrayUnion, me.arrayRemove, me.delete, (T) => S.collection("tenants").doc(i).collection("system_fields").doc(f.collection).collection(`${f.collection}-${T.name}`).doc(e), (T, C) => S.collection("tenants").doc(i).collection("system_unique").doc(f.collection).collection(`Unique-${f.collection}-${T.name}`).doc(C), (T) => S.collection("tenants").doc(i).collection("system_fields").doc(f.collection).collection(`${f.collection}-${T}`).doc(e), (T, C) => De(S, T, i).doc(C), (T, C, F) => S.collection("tenants").doc(i).collection("system_fields").doc(T.collection).collection(`${T.collection}-${C}`).doc(F), (T, C, F) => S.collection("tenants").doc(i).collection("system_fields").doc(T.collection).collection(`${T.collection}-${C.replaceAll(" ", "-")}`).doc(F)), w.delete(p.doc(e));
11142
11146
  }, { maxAttempts: 10 });
11143
- } catch (E) {
11144
- const R = await ae("postWriteError", o, y, ["delete", C, e, r, E]);
11145
- if (m && (await new Promise((F) => {
11146
- setTimeout(F, 250);
11147
- }), await Mt("delete", R?.resolved ? "success" : "failed", C, i, n, e, h, R?.resolved ? void 0 : E)), !R?.resolved)
11148
- throw h.auth && C.User_ID && await b.collection("tenants").doc(i).collection(f.collection).doc(e).update({ User_ID: me.delete() }), E;
11149
- }
11150
- const O = ["delete", C, e, r], _ = [...O];
11151
- return await ae("postWrite", o, y, O), await ae("postOperation", o, y, _), { id: e, ...C };
11147
+ } catch (w) {
11148
+ const T = await ae("postWriteError", o, y, ["delete", A, e, r, w]);
11149
+ if (m && (await new Promise((C) => {
11150
+ setTimeout(C, 250);
11151
+ }), await Mt("delete", T?.resolved ? "success" : "failed", A, i, n, e, h, T?.resolved ? void 0 : w)), !T?.resolved)
11152
+ throw h.auth && A.User_ID && await S.collection("tenants").doc(i).collection(f.collection).doc(e).update({ User_ID: me.delete() }), w;
11153
+ }
11154
+ const k = ["delete", A, e, r], E = [...k];
11155
+ return await ae("postWrite", o, y, k), await ae("postOperation", o, y, E), { id: e, ...A };
11152
11156
  }, wu = async (n, e) => {
11153
11157
  const t = ue(), s = To(), r = process.env.ADMIN_SMS;
11154
11158
  if (s === "development")
@@ -11170,16 +11174,16 @@ ${i}`);
11170
11174
  e(n);
11171
11175
  }, Eu = async (n) => await gt().getUser(n), vu = (n) => {
11172
11176
  const e = Ro();
11173
- return V.fromJSDate(n).setZone(e);
11177
+ return P.fromJSDate(n).setZone(e);
11174
11178
  }, Gc = (n) => {
11175
11179
  const e = Ro();
11176
- return V.fromJSDate(n.toDate()).setZone(e);
11180
+ return P.fromJSDate(n.toDate()).setZone(e);
11177
11181
  }, Ou = (n, e) => {
11178
- const s = V.fromJSDate(n, { zone: e }).offset, i = V.fromJSDate(n).offset, o = s - i;
11179
- return V.fromJSDate(n).plus({ minutes: o }).toJSDate();
11182
+ const s = P.fromJSDate(n, { zone: e }).offset, i = P.fromJSDate(n).offset, o = s - i;
11183
+ return P.fromJSDate(n).plus({ minutes: o }).toJSDate();
11180
11184
  }, ku = (n, e) => {
11181
- const s = V.fromJSDate(n, { zone: e }).offset, i = V.fromJSDate(n).offset, o = s - i;
11182
- return V.fromJSDate(n).minus({ minutes: o }).toJSDate();
11185
+ const s = P.fromJSDate(n, { zone: e }).offset, i = P.fromJSDate(n).offset, o = s - i;
11186
+ return P.fromJSDate(n).minus({ minutes: o }).toJSDate();
11183
11187
  }, bu = (n) => "seconds" in n && "nanoseconds" in n ? Gc(new lt(n.seconds, n.nanoseconds)).toFormat("MMMM d, yyyy '@' h:mm a") : "";
11184
11188
  export {
11185
11189
  yu as addRecord,