@voltro/plugin-guilds 0.90.0 → 0.91.1

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/service.js CHANGED
@@ -1,99 +1,99 @@
1
- import { GuildsError as e, guildsError as t } from "./errors.js";
2
- import { guildsUnavailable as n } from "./unavailable.server.js";
3
- import { GuildAnnouncementSchema as r, GuildApplicationSchema as i, GuildInviteSchema as a, GuildLogSchema as o, GuildMemberSchema as s, GuildRoleSchema as c, GuildSchema as l, GuildSummarySchema as u } from "./contract.js";
4
- import { guildAdmissionsTable as d, guildAnnouncementsTable as f, guildApplicationsTable as p, guildInvitesTable as m, guildLogTable as h, guildMembersTable as g, guildRolesTable as _, guildTables as v, guildsTable as y } from "./entities.js";
5
- import { Effect as b, Schema as x } from "effect";
6
- import { and as S, eq as C, isNull as ee, or as w, queryFor as te } from "@voltro/database";
7
- import { createHash as ne, randomUUID as re } from "node:crypto";
1
+ import { guildsUnavailable as e } from "./unavailable.server.js";
2
+ import { guildAdmissionsTable as t, guildAnnouncementsTable as n, guildApplicationsTable as r, guildInvitesTable as i, guildLogTable as a, guildMembersTable as o, guildRolesTable as s, guildTables as c, guildsTable as l } from "./entities.js";
3
+ import { GuildAnnouncementSchema as u, GuildApplicationSchema as d, GuildInviteSchema as f, GuildLogSchema as p, GuildMemberSchema as m, GuildRoleSchema as h, GuildSchema as g, GuildSummarySchema as ee } from "./contract.js";
4
+ import { GuildsError as _, guildsError as v } from "./errors.js";
5
+ import { Effect as y, Schema as b } from "effect";
6
+ import { and as x, eq as S, isNull as te, or as C, queryFor as ne } from "@voltro/database";
7
+ import { createHash as w, randomUUID as re } from "node:crypto";
8
8
  import { keywordProvider as ie } from "@voltro/plugin-moderation";
9
9
  import { SocialBlockPort as ae } from "@voltro/plugin-social/port";
10
10
  // src/service.ts
11
- var T = (e) => ne("sha256").update(JSON.stringify(e)).digest("hex"), E = (e, t) => e + "_" + T(t).slice(0, 56), D = (t) => t instanceof e ? t : n(t), O = (e) => b.tryPromise({
11
+ var T = (e) => w("sha256").update(JSON.stringify(e)).digest("hex"), E = (e, t) => e + "_" + T(t).slice(0, 56), D = (t) => t instanceof _ ? t : e(t), O = (e) => y.tryPromise({
12
12
  try: e,
13
13
  catch: D
14
- }), k = (e) => b.try({
14
+ }), k = (e) => y.try({
15
15
  try: e,
16
16
  catch: D
17
17
  }), A = (e) => {
18
- if (typeof e != "string" || !e.trim() || e.length > 256 || e.includes("\0") || e === "~") throw t("invalid_input");
18
+ if (typeof e != "string" || !e.trim() || e.length > 256 || e.includes("\0") || e === "~") throw v("invalid_input");
19
19
  }, j = (e) => {
20
- if (e.type !== "user") throw t("identity_required");
20
+ if (e.type !== "user") throw v("identity_required");
21
21
  return A(e.id), A(e.tenantId), e;
22
- }, M = (e, n) => {
23
- let r = e[n];
24
- if (typeof r != "string") throw t("unavailable");
25
- return r;
26
- }, N = (e) => {
27
- let n = e instanceof Date ? e.getTime() : typeof e == "string" ? Date.parse(e) : NaN;
28
- if (!Number.isSafeInteger(n) || n < 0) throw t("unavailable");
22
+ }, M = (e, t) => {
23
+ let n = e[t];
24
+ if (typeof n != "string") throw v("unavailable");
29
25
  return n;
26
+ }, N = (e) => {
27
+ let t = e instanceof Date ? e.getTime() : typeof e == "string" ? Date.parse(e) : NaN;
28
+ if (!Number.isSafeInteger(t) || t < 0) throw v("unavailable");
29
+ return t;
30
30
  }, P = (e) => e === !0 || e === 1, F = (e, t, n = [], r = []) => {
31
31
  let i = { ...t };
32
32
  for (let e of n) i[e] = i[e] === null ? null : N(i[e]);
33
33
  for (let e of r) i[e] = P(i[e]);
34
- return x.decodeUnknownSync(e)(i);
35
- }, I = (e) => F(l, e, ["createdAt"]), L = (e) => F(s, e, ["joinedAt", "lastActiveAt"]), R = (e) => F(i, e, ["createdAt", "decidedAt"]), z = (e) => F(a, e, ["createdAt", "expiresAt"]), B = (i, a) => {
36
- let s = () => {
37
- let e = a.now();
38
- if (!Number.isSafeInteger(e) || e < 0 || e > 864e13) throw t("unavailable");
34
+ return b.decodeUnknownSync(e)(i);
35
+ }, I = (e) => F(g, e, ["createdAt"]), L = (e) => F(m, e, ["joinedAt", "lastActiveAt"]), R = (e) => F(d, e, ["createdAt", "decidedAt"]), z = (e) => F(f, e, ["createdAt", "expiresAt"]), B = (d, f) => {
36
+ let m = () => {
37
+ let e = f.now();
38
+ if (!Number.isSafeInteger(e) || e < 0 || e > 864e13) throw v("unavailable");
39
39
  return e;
40
- }, l = (e, n, r = !1) => {
41
- if (typeof e != "string" || !r && !e.trim() || [...e].length > n || /[\u0000-\u0008\u000b\u000c\u000e-\u001f]/u.test(e)) throw t("invalid_input");
40
+ }, g = (e, t, n = !1) => {
41
+ if (typeof e != "string" || !n && !e.trim() || [...e].length > t || /[\u0000-\u0008\u000b\u000c\u000e-\u001f]/u.test(e)) throw v("invalid_input");
42
42
  return e;
43
- }, x = (e) => {
44
- let n = l(e, 64).normalize("NFKC").trim().replace(/\s+/gu, " ");
45
- if ([...n].length < 3 || [...n].length > 64) throw t("invalid_input");
46
- return n;
47
- }, ne = (e) => {
48
- if (typeof e != "string" || !/^[a-zA-Z0-9]{3,5}$/u.test(e)) throw t("invalid_input");
43
+ }, b = (e) => {
44
+ let t = g(e, 64).normalize("NFKC").trim().replace(/\s+/gu, " ");
45
+ if ([...t].length < 3 || [...t].length > 64) throw v("invalid_input");
46
+ return t;
47
+ }, w = (e) => {
48
+ if (typeof e != "string" || !/^[a-zA-Z0-9]{3,5}$/u.test(e)) throw v("invalid_input");
49
49
  return e.toUpperCase();
50
- }, D = (e) => e == null ? null : l(e, 64), B = (e, t, n) => E("gmem", [
50
+ }, D = (e) => e == null ? null : g(e, 64), B = (e, t, n) => E("gmem", [
51
51
  e,
52
52
  t,
53
53
  n
54
- ]), V = (e, t) => E("grole", [e, t]), H = (e, t) => E("gadm", [e, t]), U = (e, t, n, r = a.maxExportRows + 1) => e.query(te(t).where(n).orderBy("id", "asc").limit(r).descriptor), W = async (e, n, r, i) => {
55
- A(i);
56
- let a = (await U(e, n, C("id", i), 1))[0];
57
- if (!a || a.tenantId !== r) throw t("not_found");
58
- return a;
59
- }, G = async (e, n, r) => {
60
- let i = await W(e, y, n, r);
61
- if (i.dissolvedAt !== null) throw t("not_found");
54
+ ]), V = (e, t) => E("grole", [e, t]), H = (e, t) => E("gadm", [e, t]), U = (e, t, n, r = f.maxExportRows + 1) => e.query(ne(t).where(n).orderBy("id", "asc").limit(r).descriptor), W = async (e, t, n, r) => {
55
+ A(r);
56
+ let i = (await U(e, t, S("id", r), 1))[0];
57
+ if (!i || i.tenantId !== n) throw v("not_found");
62
58
  return i;
63
- }, K = async (e, n, r, i) => {
64
- let a = await W(e, g, n, B(n, r, i));
65
- if (a.guildId !== r || a.subjectId !== i) throw t("unavailable");
66
- return a;
67
- }, q = async (e, n, r, i) => {
68
- let a = await W(e, _, n, M(i, "roleId"));
69
- if (a.guildId !== r) throw t("unavailable");
70
- return F(c, a);
71
- }, J = async (e, n, r, i) => {
72
- let o = await K(e, n.tenantId, r, n.id), s = await q(e, n.tenantId, r, o);
73
- if (a.strategies.permissions({
74
- role: s,
75
- permission: i
76
- }) !== !0) throw t("forbidden");
59
+ }, G = async (e, t, n) => {
60
+ let r = await W(e, l, t, n);
61
+ if (r.dissolvedAt !== null) throw v("not_found");
62
+ return r;
63
+ }, K = async (e, t, n, r) => {
64
+ let i = await W(e, o, t, B(t, n, r));
65
+ if (i.guildId !== n || i.subjectId !== r) throw v("unavailable");
66
+ return i;
67
+ }, q = async (e, t, n, r) => {
68
+ let i = await W(e, s, t, M(r, "roleId"));
69
+ if (i.guildId !== n) throw v("unavailable");
70
+ return F(h, i);
71
+ }, J = async (e, t, n, r) => {
72
+ let i = await K(e, t.tenantId, n, t.id), a = await q(e, t.tenantId, n, i);
73
+ if (f.strategies.permissions({
74
+ role: a,
75
+ permission: r
76
+ }) !== !0) throw v("forbidden");
77
77
  return {
78
- member: o,
79
- role: s
78
+ member: i,
79
+ role: a
80
80
  };
81
- }, oe = async (e, t) => {
82
- for (let n of [...new Set(t)].sort()) {
83
- A(n);
84
- let t = H(e, n);
81
+ }, oe = async (e, n) => {
82
+ for (let r of [...new Set(n)].sort()) {
83
+ A(r);
84
+ let n = H(e, r);
85
85
  try {
86
- await i.insertIgnore(d.tableName, {
87
- id: t,
86
+ await d.insertIgnore(t.tableName, {
87
+ id: n,
88
88
  tenantId: e,
89
- subjectId: n,
89
+ subjectId: r,
90
90
  admission: 0,
91
91
  erased: !1,
92
92
  metadata: {}
93
93
  }, { conflictColumns: ["id"] });
94
- } catch (r) {
95
- let a = (await U(i, d, C("id", t), 1))[0];
96
- if (!a || a.tenantId !== e || a.subjectId !== n && !P(a.erased)) throw r;
94
+ } catch (i) {
95
+ let a = (await U(d, t, S("id", n), 1))[0];
96
+ if (!a || a.tenantId !== e || a.subjectId !== r && !P(a.erased)) throw i;
97
97
  }
98
98
  }
99
99
  }, Y = async (e, n, r, i = !1, a = async () => {}) => {
@@ -101,83 +101,83 @@ var T = (e) => ne("sha256").update(JSON.stringify(e)).digest("hex"), E = (e, t)
101
101
  subject: e,
102
102
  key: H(n, e)
103
103
  })).sort((e, t) => e.key < t.key ? -1 : 1);
104
- for (let { key: n } of o) if (await e.updateMany(d.tableName, { admission: 0 }, { where: C("id", n) }) !== 1) throw t("unavailable");
104
+ for (let { key: n } of o) if (await e.updateMany(t.tableName, { admission: 0 }, { where: S("id", n) }) !== 1) throw v("unavailable");
105
105
  await a();
106
106
  for (let { subject: r, key: a } of o) {
107
- let o = await W(e, d, n, a);
107
+ let o = await W(e, t, n, a);
108
108
  if (P(o.erased)) {
109
- if (!i) throw t("identity_required");
110
- } else if (o.subjectId !== r) throw t("unavailable");
109
+ if (!i) throw v("identity_required");
110
+ } else if (o.subjectId !== r) throw v("unavailable");
111
111
  }
112
- }, X = async (e, n, r, a) => {
113
- A(n);
114
- let o = [e.id, ...r];
115
- return await oe(e.tenantId, o), i.transactional(async (r) => (await Y(r, e.tenantId, o, !1, async () => {
116
- if (await r.updateMany(y.tableName, { admission: 0 }, { where: C("id", n) }) !== 1) throw t("not_found");
117
- }), a(r, await G(r, e.tenantId, n))));
118
- }, Z = (e, n, r) => {
119
- if (e.length > a.maxExportRows || e.some((e) => e.tenantId !== n || r !== void 0 && e.guildId !== r)) throw t("unavailable");
112
+ }, X = async (e, t, n, r) => {
113
+ A(t);
114
+ let i = [e.id, ...n];
115
+ return await oe(e.tenantId, i), d.transactional(async (n) => (await Y(n, e.tenantId, i, !1, async () => {
116
+ if (await n.updateMany(l.tableName, { admission: 0 }, { where: S("id", t) }) !== 1) throw v("not_found");
117
+ }), r(n, await G(n, e.tenantId, t))));
118
+ }, Z = (e, t, n) => {
119
+ if (e.length > f.maxExportRows || e.some((e) => e.tenantId !== t || n !== void 0 && e.guildId !== n)) throw v("unavailable");
120
120
  return e;
121
- }, Q = (e, t, n, r, i, a = {}, o = re()) => e.insert(h.tableName, {
121
+ }, Q = (e, t, n, r, i, o = {}, s = re()) => e.insert(a.tableName, {
122
122
  id: E("glog", [
123
123
  t.tenantId,
124
124
  t.id,
125
125
  n,
126
- o
126
+ s
127
127
  ]),
128
128
  tenantId: t.tenantId,
129
129
  guildId: t.id,
130
130
  kind: n,
131
131
  actorId: r,
132
132
  targetId: i,
133
- detail: a,
134
- at: new Date(s())
135
- }), se = async (e, n, r) => {
136
- let i = M(n, "tenantId"), o = M(n, "id"), c = B(i, o, r), l = (await U(e, g, C("id", c), 1))[0];
137
- if (l) {
138
- if (l.tenantId !== i || l.subjectId !== r || l.guildId !== o) throw t("unavailable");
139
- return L(l);
133
+ detail: o,
134
+ at: new Date(m())
135
+ }), se = async (e, t, n) => {
136
+ let r = M(t, "tenantId"), i = M(t, "id"), a = B(r, i, n), s = (await U(e, o, S("id", a), 1))[0];
137
+ if (s) {
138
+ if (s.tenantId !== r || s.subjectId !== n || s.guildId !== i) throw v("unavailable");
139
+ return L(s);
140
140
  }
141
- let u = Z(await U(e, g, S(C("tenantId", i), C("subjectId", r))), i);
142
- if (u.some((e) => e.subjectId !== r)) throw t("unavailable");
143
- if (u.length >= a.maxGuildsPerSubject) throw t("guild_limit");
144
- if (Z(await U(e, g, S(C("tenantId", i), C("guildId", o))), i, o).length >= Number(n.memberCap)) throw t("member_limit");
145
- return L(await e.insert(g.tableName, {
146
- id: c,
147
- tenantId: i,
148
- guildId: o,
149
- subjectId: r,
150
- roleId: V(o, "member"),
151
- joinedAt: new Date(s()),
152
- lastActiveAt: new Date(s()),
141
+ let c = Z(await U(e, o, x(S("tenantId", r), S("subjectId", n))), r);
142
+ if (c.some((e) => e.subjectId !== n)) throw v("unavailable");
143
+ if (c.length >= f.maxGuildsPerSubject) throw v("guild_limit");
144
+ if (Z(await U(e, o, x(S("tenantId", r), S("guildId", i))), r, i).length >= Number(t.memberCap)) throw v("member_limit");
145
+ return L(await e.insert(o.tableName, {
146
+ id: a,
147
+ tenantId: r,
148
+ guildId: i,
149
+ subjectId: n,
150
+ roleId: V(i, "member"),
151
+ joinedAt: new Date(m()),
152
+ lastActiveAt: new Date(m()),
153
153
  contribution: {},
154
154
  metadata: {}
155
155
  }));
156
- }, $ = (e) => ie(a.denyWords)(e).pipe(b.flatMap((n) => n.flagged ? b.fail(t("content_rejected")) : b.succeed(e)), b.catchDefect((e) => b.fail(n(e)))), ce = async (e, n, r, i = !1) => {
157
- let a = M(n, "tenantId"), o = M(n, "id"), s = M(n, "ownerId"), c = await K(e, a, o, r);
158
- if (s === r) return I(n);
159
- if (!i) {
160
- let t = await K(e, a, o, s);
161
- await e.update(g.tableName, M(t, "id"), { roleId: V(o, "officer") });
156
+ }, $ = (t) => ie(f.denyWords)(t).pipe(y.flatMap((e) => e.flagged ? y.fail(v("content_rejected")) : y.succeed(t)), y.catchDefect((t) => y.fail(e(t)))), ce = async (e, t, n, r = !1) => {
157
+ let i = M(t, "tenantId"), a = M(t, "id"), s = M(t, "ownerId"), c = await K(e, i, a, n);
158
+ if (s === n) return I(t);
159
+ if (!r) {
160
+ let t = await K(e, i, a, s);
161
+ await e.update(o.tableName, M(t, "id"), { roleId: V(a, "officer") });
162
162
  }
163
- await e.update(g.tableName, M(c, "id"), { roleId: V(o, "owner") });
164
- let l = await e.update(y.tableName, o, {
165
- ownerId: r,
166
- version: Number(n.version) + 1
163
+ await e.update(o.tableName, M(c, "id"), { roleId: V(a, "owner") });
164
+ let u = await e.update(l.tableName, a, {
165
+ ownerId: n,
166
+ version: Number(t.version) + 1
167
167
  });
168
- if (!l) throw t("unavailable");
169
- return await Q(e, n, "ownerTransferred", i ? null : s, r), I(l);
168
+ if (!u) throw v("unavailable");
169
+ return await Q(e, t, "ownerTransferred", r ? null : s, n), I(u);
170
170
  }, le = async (e, t, n, r) => {
171
- let i = M(t, "tenantId"), a = M(t, "id"), o = await K(e, i, a, n);
171
+ let i = M(t, "tenantId"), a = M(t, "id"), s = await K(e, i, a, n);
172
172
  if (t.ownerId === n) {
173
- let r = Z(await U(e, g, S(C("tenantId", i), C("guildId", a))), i, a), o = [];
174
- for (let t of r) t.subjectId !== n && o.push({
173
+ let r = Z(await U(e, o, x(S("tenantId", i), S("guildId", a))), i, a), s = [];
174
+ for (let t of r) t.subjectId !== n && s.push({
175
175
  row: t,
176
176
  role: await q(e, i, a, t)
177
177
  });
178
- o.sort((e, t) => e.role.rank - t.role.rank || N(e.row.joinedAt) - N(t.row.joinedAt) || (M(e.row, "subjectId") < M(t.row, "subjectId") ? -1 : 1)), o[0] ? await ce(e, t, M(o[0].row, "subjectId"), !0) : await e.update(y.tableName, a, {
178
+ s.sort((e, t) => e.role.rank - t.role.rank || N(e.row.joinedAt) - N(t.row.joinedAt) || (M(e.row, "subjectId") < M(t.row, "subjectId") ? -1 : 1)), s[0] ? await ce(e, t, M(s[0].row, "subjectId"), !0) : await e.update(l.tableName, a, {
179
179
  ownerId: null,
180
- dissolvedAt: new Date(s()),
180
+ dissolvedAt: new Date(m()),
181
181
  version: Number(t.version) + 1,
182
182
  name: "",
183
183
  description: "",
@@ -196,77 +196,77 @@ var T = (e) => ne("sha256").update(JSON.stringify(e)).digest("hex"), E = (e, t)
196
196
  metadata: {}
197
197
  });
198
198
  }
199
- await e.delete(g.tableName, M(o, "id")), r || await Q(e, t, "left", n, n);
199
+ await e.delete(o.tableName, M(s, "id")), r || await Q(e, t, "left", n, n);
200
200
  }, ue = {
201
- create: (n, r) => b.gen(function* () {
202
- let o = yield* k(() => {
203
- let e = j(n);
204
- A(r.requestId);
205
- let i = x(r.name), o = ne(r.tag), s = l(r.description ?? "", a.maxDescriptionLength, !0), c = r.visibility ?? "open";
201
+ create: (e, t) => y.gen(function* () {
202
+ let n = yield* k(() => {
203
+ let n = j(e);
204
+ A(t.requestId);
205
+ let r = b(t.name), i = w(t.tag), a = g(t.description ?? "", f.maxDescriptionLength, !0), o = t.visibility ?? "open";
206
206
  if (![
207
207
  "open",
208
208
  "apply",
209
209
  "invite"
210
- ].includes(c)) throw t("invalid_input");
210
+ ].includes(o)) throw v("invalid_input");
211
211
  return {
212
- who: e,
213
- guildName: i,
214
- guildTag: o,
215
- description: s,
216
- visibility: c,
217
- region: D(r.region),
218
- language: D(r.language)
212
+ who: n,
213
+ guildName: r,
214
+ guildTag: i,
215
+ description: a,
216
+ visibility: o,
217
+ region: D(t.region),
218
+ language: D(t.language)
219
219
  };
220
220
  });
221
- return yield* $(o.guildName + "\n" + o.description), yield* O(async () => {
222
- let { who: n, guildName: c, guildTag: l, description: u, visibility: d, region: f, language: p } = o, m = E("guild", [
223
- n.tenantId,
224
- n.id,
225
- r.requestId
226
- ]), h = T([
227
- n.id,
221
+ return yield* $(n.guildName + "\n" + n.description), yield* O(async () => {
222
+ let { who: e, guildName: r, guildTag: i, description: a, visibility: c, region: u, language: p } = n, h = E("guild", [
223
+ e.tenantId,
224
+ e.id,
225
+ t.requestId
226
+ ]), g = T([
227
+ e.id,
228
+ r,
229
+ i,
230
+ a,
228
231
  c,
229
- l,
230
232
  u,
231
- d,
232
- f,
233
233
  p
234
234
  ]);
235
- await oe(n.tenantId, [n.id]);
235
+ await oe(e.tenantId, [e.id]);
236
236
  try {
237
- return await i.transactional(async (e) => {
238
- await Y(e, n.tenantId, [n.id]);
239
- let i = (await U(e, y, C("id", m), 1))[0];
240
- if (i) {
241
- if (i.tenantId !== n.tenantId || i.creationKey !== h || i.dissolvedAt !== null) throw t("conflict");
242
- return I(i);
237
+ return await d.transactional(async (n) => {
238
+ await Y(n, e.tenantId, [e.id]);
239
+ let d = (await U(n, l, S("id", h), 1))[0];
240
+ if (d) {
241
+ if (d.tenantId !== e.tenantId || d.creationKey !== g || d.dissolvedAt !== null) throw v("conflict");
242
+ return I(d);
243
243
  }
244
- let o = Z(await U(e, g, S(C("tenantId", n.tenantId), C("subjectId", n.id))), n.tenantId);
245
- if (o.some((e) => e.subjectId !== n.id)) throw t("unavailable");
246
- if (o.length >= a.maxGuildsPerSubject) throw t("guild_limit");
247
- let v = T([n.tenantId, c.toLowerCase()]), b = T([n.tenantId, l]);
248
- if ((await U(e, y, w(C("nameKey", v), C("tagKey", b)), 1)).length) throw t("name_taken");
249
- let x = await e.insert(y.tableName, {
250
- id: m,
251
- tenantId: n.tenantId,
252
- name: c,
253
- nameKey: v,
254
- tag: l,
255
- tagKey: b,
256
- description: u,
244
+ let ee = Z(await U(n, o, x(S("tenantId", e.tenantId), S("subjectId", e.id))), e.tenantId);
245
+ if (ee.some((t) => t.subjectId !== e.id)) throw v("unavailable");
246
+ if (ee.length >= f.maxGuildsPerSubject) throw v("guild_limit");
247
+ let _ = T([e.tenantId, r.toLowerCase()]), y = T([e.tenantId, i]);
248
+ if ((await U(n, l, C(S("nameKey", _), S("tagKey", y)), 1)).length) throw v("name_taken");
249
+ let b = await n.insert(l.tableName, {
250
+ id: h,
251
+ tenantId: e.tenantId,
252
+ name: r,
253
+ nameKey: _,
254
+ tag: i,
255
+ tagKey: y,
256
+ description: a,
257
257
  emblem: null,
258
- visibility: d,
258
+ visibility: c,
259
259
  minLevel: 0,
260
- region: f,
260
+ region: u,
261
261
  language: p,
262
262
  level: 1,
263
263
  xp: 0,
264
- memberCap: a.baseMemberCap,
265
- createdAt: new Date(s()),
266
- ownerId: n.id,
264
+ memberCap: f.baseMemberCap,
265
+ createdAt: new Date(m()),
266
+ ownerId: e.id,
267
267
  version: 0,
268
268
  admission: 0,
269
- creationKey: h,
269
+ creationKey: g,
270
270
  dissolvedAt: null,
271
271
  metadata: {}
272
272
  });
@@ -286,499 +286,499 @@ var T = (e) => ne("sha256").update(JSON.stringify(e)).digest("hex"), E = (e, t)
286
286
  100,
287
287
  0
288
288
  ]
289
- ]) await e.insert(_.tableName, {
290
- id: V(m, t),
291
- tenantId: n.tenantId,
292
- guildId: m,
289
+ ]) await n.insert(s.tableName, {
290
+ id: V(h, t),
291
+ tenantId: e.tenantId,
292
+ guildId: h,
293
293
  name: t,
294
294
  rank: r,
295
295
  permissions: i,
296
296
  metadata: {}
297
297
  });
298
- return await e.insert(g.tableName, {
299
- id: B(n.tenantId, m, n.id),
300
- tenantId: n.tenantId,
301
- guildId: m,
302
- subjectId: n.id,
303
- roleId: V(m, "owner"),
304
- joinedAt: new Date(s()),
305
- lastActiveAt: new Date(s()),
298
+ return await n.insert(o.tableName, {
299
+ id: B(e.tenantId, h, e.id),
300
+ tenantId: e.tenantId,
301
+ guildId: h,
302
+ subjectId: e.id,
303
+ roleId: V(h, "owner"),
304
+ joinedAt: new Date(m()),
305
+ lastActiveAt: new Date(m()),
306
306
  contribution: {},
307
307
  metadata: {}
308
- }), await Q(e, x, "created", n.id, null, {}, r.requestId), I(x);
308
+ }), await Q(n, b, "created", e.id, null, {}, t.requestId), I(b);
309
309
  });
310
- } catch (r) {
311
- if (r instanceof e) throw r;
312
- let a = await U(i, y, w(C("nameKey", T([n.tenantId, c.toLowerCase()])), C("tagKey", T([n.tenantId, l]))), 1);
313
- throw a.length && a[0]?.id !== m ? t("name_taken") : r;
310
+ } catch (t) {
311
+ if (t instanceof _) throw t;
312
+ let n = await U(d, l, C(S("nameKey", T([e.tenantId, r.toLowerCase()])), S("tagKey", T([e.tenantId, i]))), 1);
313
+ throw n.length && n[0]?.id !== h ? v("name_taken") : t;
314
314
  }
315
315
  });
316
316
  }),
317
317
  mine: (e) => O(async () => {
318
- let n = j(e), r = Z(await U(i, g, S(C("tenantId", n.tenantId), C("subjectId", n.id))), n.tenantId);
319
- if (r.some((e) => e.subjectId !== n.id)) throw t("unavailable");
320
- return Promise.all(r.map(async (e) => I(await G(i, n.tenantId, M(e, "guildId")))));
318
+ let t = j(e), n = Z(await U(d, o, x(S("tenantId", t.tenantId), S("subjectId", t.id))), t.tenantId);
319
+ if (n.some((e) => e.subjectId !== t.id)) throw v("unavailable");
320
+ return Promise.all(n.map(async (e) => I(await G(d, t.tenantId, M(e, "guildId")))));
321
321
  }),
322
322
  get: (e, t) => O(async () => {
323
323
  let n = j(e);
324
- return await K(i, n.tenantId, t, n.id), I(await G(i, n.tenantId, t));
324
+ return await K(d, n.tenantId, t, n.id), I(await G(d, n.tenantId, t));
325
325
  }),
326
326
  search: (e, t) => O(async () => {
327
- let n = j(e), r = [C("tenantId", n.tenantId), ee("dissolvedAt")];
328
- return t.name !== void 0 && r.push(C("nameKey", T([n.tenantId, x(t.name).toLowerCase()]))), t.tag !== void 0 && r.push(C("tagKey", T([n.tenantId, ne(t.tag)]))), t.region !== void 0 && r.push(C("region", D(t.region))), t.language !== void 0 && r.push(C("language", D(t.language))), Z(await U(i, y, S(...r), a.pageSize), n.tenantId).map((e) => F(u, e, ["createdAt"]));
327
+ let n = j(e), r = [S("tenantId", n.tenantId), te("dissolvedAt")];
328
+ return t.name !== void 0 && r.push(S("nameKey", T([n.tenantId, b(t.name).toLowerCase()]))), t.tag !== void 0 && r.push(S("tagKey", T([n.tenantId, w(t.tag)]))), t.region !== void 0 && r.push(S("region", D(t.region))), t.language !== void 0 && r.push(S("language", D(t.language))), Z(await U(d, l, x(...r), f.pageSize), n.tenantId).map((e) => F(ee, e, ["createdAt"]));
329
329
  }),
330
330
  members: (e, t) => O(async () => {
331
331
  let n = j(e);
332
- return await G(i, n.tenantId, t), await K(i, n.tenantId, t, n.id), Z(await U(i, g, S(C("tenantId", n.tenantId), C("guildId", t))), n.tenantId, t).map(L);
332
+ return await G(d, n.tenantId, t), await K(d, n.tenantId, t, n.id), Z(await U(d, o, x(S("tenantId", n.tenantId), S("guildId", t))), n.tenantId, t).map(L);
333
333
  }),
334
334
  roles: (e, t) => O(async () => {
335
335
  let n = j(e);
336
- return await G(i, n.tenantId, t), await K(i, n.tenantId, t, n.id), Z(await U(i, _, S(C("tenantId", n.tenantId), C("guildId", t))), n.tenantId, t).map((e) => F(c, e));
336
+ return await G(d, n.tenantId, t), await K(d, n.tenantId, t, n.id), Z(await U(d, s, x(S("tenantId", n.tenantId), S("guildId", t))), n.tenantId, t).map((e) => F(h, e));
337
337
  }),
338
- join: (e, n) => O(async () => {
339
- let r = j(e);
340
- return X(r, n, [], async (e, i) => {
341
- if (i.visibility !== "open") throw t("forbidden");
342
- let a = (await U(e, g, C("id", B(r.tenantId, n, r.id)), 1))[0], o = await se(e, i, r.id);
343
- return a || await Q(e, i, "joined", r.id, r.id), o;
338
+ join: (e, t) => O(async () => {
339
+ let n = j(e);
340
+ return X(n, t, [], async (e, r) => {
341
+ if (r.visibility !== "open") throw v("forbidden");
342
+ let i = (await U(e, o, S("id", B(n.tenantId, t, n.id)), 1))[0], a = await se(e, r, n.id);
343
+ return i || await Q(e, r, "joined", n.id, n.id), a;
344
344
  });
345
345
  }),
346
346
  leave: (e, t) => O(async () => {
347
347
  let n = j(e);
348
348
  return X(n, t, [], (e, t) => le(e, t, n.id, !1));
349
349
  }),
350
- apply: (e, n) => b.gen(function* () {
351
- let r = yield* k(() => {
352
- let t = j(e);
353
- return A(n.requestId), l(n.message, a.maxDescriptionLength, !0), t;
350
+ apply: (e, t) => y.gen(function* () {
351
+ let n = yield* k(() => {
352
+ let n = j(e);
353
+ return A(t.requestId), g(t.message, f.maxDescriptionLength, !0), n;
354
354
  });
355
- return yield* $(n.message), yield* O(() => X(r, n.guildId, [], async (e, i) => {
356
- if (i.visibility !== "apply") throw t("forbidden");
357
- let o = E("gapp", [
358
- r.tenantId,
359
- n.guildId,
360
- r.id,
361
- n.requestId
362
- ]), c = (await U(e, p, C("id", o), 1))[0];
363
- if (c) {
364
- if (c.tenantId !== r.tenantId || c.subjectId !== r.id || c.guildId !== n.guildId || c.message !== n.message) throw t("conflict");
365
- return R(c);
355
+ return yield* $(t.message), yield* O(() => X(n, t.guildId, [], async (e, i) => {
356
+ if (i.visibility !== "apply") throw v("forbidden");
357
+ let a = E("gapp", [
358
+ n.tenantId,
359
+ t.guildId,
360
+ n.id,
361
+ t.requestId
362
+ ]), o = (await U(e, r, S("id", a), 1))[0];
363
+ if (o) {
364
+ if (o.tenantId !== n.tenantId || o.subjectId !== n.id || o.guildId !== t.guildId || o.message !== t.message) throw v("conflict");
365
+ return R(o);
366
366
  }
367
- let l = Z(await U(e, p, S(C("tenantId", r.tenantId), C("guildId", n.guildId), C("state", "pending"))), r.tenantId, n.guildId);
368
- if (l.some((e) => e.subjectId === r.id)) throw t("conflict");
369
- if (l.length >= a.maxPending) throw t("pending_limit");
370
- return R(await e.insert(p.tableName, {
371
- id: o,
372
- tenantId: r.tenantId,
373
- guildId: n.guildId,
374
- subjectId: r.id,
375
- message: n.message,
367
+ let s = Z(await U(e, r, x(S("tenantId", n.tenantId), S("guildId", t.guildId), S("state", "pending"))), n.tenantId, t.guildId);
368
+ if (s.some((e) => e.subjectId === n.id)) throw v("conflict");
369
+ if (s.length >= f.maxPending) throw v("pending_limit");
370
+ return R(await e.insert(r.tableName, {
371
+ id: a,
372
+ tenantId: n.tenantId,
373
+ guildId: t.guildId,
374
+ subjectId: n.id,
375
+ message: t.message,
376
376
  state: "pending",
377
377
  decidedBy: null,
378
378
  decidedAt: null,
379
- createdAt: new Date(s()),
379
+ createdAt: new Date(m()),
380
380
  metadata: {}
381
381
  }));
382
382
  }));
383
383
  }),
384
384
  applications: (e, t) => O(async () => {
385
385
  let n = j(e);
386
- return await G(i, n.tenantId, t), await J(i, n, t, "invite"), Z(await U(i, p, S(C("tenantId", n.tenantId), C("guildId", t))), n.tenantId, t).map(R);
386
+ return await G(d, n.tenantId, t), await J(d, n, t, "invite"), Z(await U(d, r, x(S("tenantId", n.tenantId), S("guildId", t))), n.tenantId, t).map(R);
387
387
  }),
388
- decideApplication: (e, n) => O(async () => {
389
- let r = j(e);
390
- if (typeof n.accept != "boolean") throw t("invalid_input");
391
- let a = await W(i, p, r.tenantId, n.applicationId);
392
- return X(r, M(a, "guildId"), [M(a, "subjectId")], async (e, i) => {
393
- await J(e, r, M(i, "id"), "invite");
394
- let o = await W(e, p, r.tenantId, n.applicationId);
395
- if (o.guildId !== i.id || o.subjectId !== a.subjectId) throw t("unavailable");
396
- let c = n.accept ? "accepted" : "declined";
388
+ decideApplication: (e, t) => O(async () => {
389
+ let n = j(e);
390
+ if (typeof t.accept != "boolean") throw v("invalid_input");
391
+ let i = await W(d, r, n.tenantId, t.applicationId);
392
+ return X(n, M(i, "guildId"), [M(i, "subjectId")], async (e, a) => {
393
+ await J(e, n, M(a, "id"), "invite");
394
+ let o = await W(e, r, n.tenantId, t.applicationId);
395
+ if (o.guildId !== a.id || o.subjectId !== i.subjectId) throw v("unavailable");
396
+ let s = t.accept ? "accepted" : "declined";
397
397
  if (o.state !== "pending") {
398
- if (o.state !== c) throw t("conflict");
398
+ if (o.state !== s) throw v("conflict");
399
399
  return R(o);
400
400
  }
401
- n.accept && await se(e, i, M(o, "subjectId"));
402
- let l = await e.update(p.tableName, n.applicationId, {
403
- state: c,
404
- decidedBy: r.id,
405
- decidedAt: new Date(s())
401
+ t.accept && await se(e, a, M(o, "subjectId"));
402
+ let c = await e.update(r.tableName, t.applicationId, {
403
+ state: s,
404
+ decidedBy: n.id,
405
+ decidedAt: new Date(m())
406
406
  });
407
- if (!l) throw t("unavailable");
408
- return await Q(e, i, "applicationDecided", r.id, M(o, "subjectId"), { accept: n.accept }, n.applicationId), R(l);
407
+ if (!c) throw v("unavailable");
408
+ return await Q(e, a, "applicationDecided", n.id, M(o, "subjectId"), { accept: t.accept }, t.applicationId), R(c);
409
409
  });
410
410
  }),
411
- invite: (e, n) => b.gen(function* () {
412
- let r = yield* k(() => {
413
- let r = j(e);
414
- if (A(n.subjectId), A(n.requestId), r.id === n.subjectId) throw t("invalid_input");
415
- return r;
416
- }), i = yield* b.serviceOption(ae);
417
- return i._tag === "Some" && !(yield* i.value.canInvite(r, n.subjectId).pipe(b.mapError(() => t("unavailable")))) ? yield* b.fail(t("blocked")) : yield* O(() => X(r, n.guildId, [n.subjectId], async (e, i) => {
418
- await J(e, r, n.guildId, "invite");
419
- let o = E("ginv", [
420
- r.tenantId,
421
- n.guildId,
422
- r.id,
423
- n.subjectId,
424
- n.requestId
425
- ]), c = (await U(e, m, C("id", o), 1))[0];
426
- if (c) {
427
- if (c.tenantId !== r.tenantId || c.guildId !== n.guildId || c.toId !== n.subjectId || c.fromId !== r.id) throw t("conflict");
428
- return z(c);
411
+ invite: (e, t) => y.gen(function* () {
412
+ let n = yield* k(() => {
413
+ let n = j(e);
414
+ if (A(t.subjectId), A(t.requestId), n.id === t.subjectId) throw v("invalid_input");
415
+ return n;
416
+ }), r = yield* y.serviceOption(ae);
417
+ return r._tag === "Some" && !(yield* r.value.canInvite(n, t.subjectId).pipe(y.mapError(() => v("unavailable")))) ? yield* y.fail(v("blocked")) : yield* O(() => X(n, t.guildId, [t.subjectId], async (e, r) => {
418
+ await J(e, n, t.guildId, "invite");
419
+ let a = E("ginv", [
420
+ n.tenantId,
421
+ t.guildId,
422
+ n.id,
423
+ t.subjectId,
424
+ t.requestId
425
+ ]), o = (await U(e, i, S("id", a), 1))[0];
426
+ if (o) {
427
+ if (o.tenantId !== n.tenantId || o.guildId !== t.guildId || o.toId !== t.subjectId || o.fromId !== n.id) throw v("conflict");
428
+ return z(o);
429
429
  }
430
- let l = Z(await U(e, m, S(C("tenantId", r.tenantId), C("guildId", n.guildId), C("state", "pending"))), r.tenantId, n.guildId).filter((e) => N(e.expiresAt) > s());
431
- if (l.some((e) => e.toId === n.subjectId)) throw t("conflict");
432
- if (l.length >= a.maxPending) throw t("pending_limit");
433
- return z(await e.insert(m.tableName, {
434
- id: o,
435
- tenantId: r.tenantId,
436
- guildId: n.guildId,
437
- toId: n.subjectId,
438
- fromId: r.id,
439
- expiresAt: new Date(s() + a.inviteTtlMs),
430
+ let s = Z(await U(e, i, x(S("tenantId", n.tenantId), S("guildId", t.guildId), S("state", "pending"))), n.tenantId, t.guildId).filter((e) => N(e.expiresAt) > m());
431
+ if (s.some((e) => e.toId === t.subjectId)) throw v("conflict");
432
+ if (s.length >= f.maxPending) throw v("pending_limit");
433
+ return z(await e.insert(i.tableName, {
434
+ id: a,
435
+ tenantId: n.tenantId,
436
+ guildId: t.guildId,
437
+ toId: t.subjectId,
438
+ fromId: n.id,
439
+ expiresAt: new Date(m() + f.inviteTtlMs),
440
440
  state: "pending",
441
- createdAt: new Date(s()),
441
+ createdAt: new Date(m()),
442
442
  metadata: {}
443
443
  }));
444
444
  }));
445
445
  }),
446
446
  invites: (e) => O(async () => {
447
- let n = j(e), r = Z(await U(i, m, S(C("tenantId", n.tenantId), C("toId", n.id), C("state", "pending"))), n.tenantId);
448
- if (r.some((e) => e.toId !== n.id)) throw t("unavailable");
449
- return r.filter((e) => N(e.expiresAt) > s()).map(z);
447
+ let t = j(e), n = Z(await U(d, i, x(S("tenantId", t.tenantId), S("toId", t.id), S("state", "pending"))), t.tenantId);
448
+ if (n.some((e) => e.toId !== t.id)) throw v("unavailable");
449
+ return n.filter((e) => N(e.expiresAt) > m()).map(z);
450
450
  }),
451
- decideInvite: (e, n) => b.gen(function* () {
452
- let r = yield* k(() => {
453
- let r = j(e);
454
- if (typeof n.accept != "boolean") throw t("invalid_input");
455
- return r;
456
- }), o = yield* O(() => W(i, m, r.tenantId, n.inviteId));
457
- if (o.toId !== r.id) return yield* b.fail(t("forbidden"));
458
- let c = yield* b.serviceOption(ae);
459
- return n.accept && c._tag === "Some" && (yield* c.value.isBlocked(r, M(o, "fromId")).pipe(b.mapError(() => t("unavailable")))) ? yield* b.fail(t("blocked")) : yield* O(() => X(r, M(o, "guildId"), [], async (e, i) => {
460
- let o = await W(e, m, r.tenantId, n.inviteId);
461
- if (o.toId !== r.id || o.guildId !== i.id) throw t("forbidden");
462
- let c = n.accept ? "accepted" : "declined";
463
- if (o.state !== "pending") {
464
- if (o.state !== c) throw t("conflict");
465
- return z(o);
451
+ decideInvite: (e, t) => y.gen(function* () {
452
+ let n = yield* k(() => {
453
+ let n = j(e);
454
+ if (typeof t.accept != "boolean") throw v("invalid_input");
455
+ return n;
456
+ }), r = yield* O(() => W(d, i, n.tenantId, t.inviteId));
457
+ if (r.toId !== n.id) return yield* y.fail(v("forbidden"));
458
+ let a = yield* y.serviceOption(ae);
459
+ return t.accept && a._tag === "Some" && (yield* a.value.isBlocked(n, M(r, "fromId")).pipe(y.mapError(() => v("unavailable")))) ? yield* y.fail(v("blocked")) : yield* O(() => X(n, M(r, "guildId"), [], async (e, r) => {
460
+ let a = await W(e, i, n.tenantId, t.inviteId);
461
+ if (a.toId !== n.id || a.guildId !== r.id) throw v("forbidden");
462
+ let o = t.accept ? "accepted" : "declined";
463
+ if (a.state !== "pending") {
464
+ if (a.state !== o) throw v("conflict");
465
+ return z(a);
466
466
  }
467
- if (N(o.expiresAt) <= s()) throw t("expired");
468
- let l = await K(e, r.tenantId, M(i, "id"), M(o, "fromId")), u = await q(e, r.tenantId, M(i, "id"), l);
469
- if (n.accept && a.strategies.permissions({
470
- role: u,
467
+ if (N(a.expiresAt) <= m()) throw v("expired");
468
+ let s = await K(e, n.tenantId, M(r, "id"), M(a, "fromId")), c = await q(e, n.tenantId, M(r, "id"), s);
469
+ if (t.accept && f.strategies.permissions({
470
+ role: c,
471
471
  permission: "invite"
472
- }) !== !0) throw t("forbidden");
473
- n.accept && await se(e, i, r.id);
474
- let d = await e.update(m.tableName, n.inviteId, { state: c });
475
- if (!d) throw t("unavailable");
476
- return await Q(e, i, "inviteDecided", r.id, r.id, { accept: n.accept }, n.inviteId), z(d);
472
+ }) !== !0) throw v("forbidden");
473
+ t.accept && await se(e, r, n.id);
474
+ let l = await e.update(i.tableName, t.inviteId, { state: o });
475
+ if (!l) throw v("unavailable");
476
+ return await Q(e, r, "inviteDecided", n.id, n.id, { accept: t.accept }, t.inviteId), z(l);
477
477
  }));
478
478
  }),
479
- kick: (e, n, r) => O(async () => {
480
- let i = j(e);
481
- return A(r), X(i, n, [r], async (e, a) => {
482
- let o = await J(e, i, n, "kick"), s = await K(e, i.tenantId, n, r), c = await q(e, i.tenantId, n, s);
483
- if (r === i.id || a.ownerId === r || c.rank <= o.role.rank) throw t("forbidden");
484
- await e.delete(g.tableName, M(s, "id")), await Q(e, a, "kicked", i.id, r);
479
+ kick: (e, t, n) => O(async () => {
480
+ let r = j(e);
481
+ return A(n), X(r, t, [n], async (e, i) => {
482
+ let a = await J(e, r, t, "kick"), s = await K(e, r.tenantId, t, n), c = await q(e, r.tenantId, t, s);
483
+ if (n === r.id || i.ownerId === n || c.rank <= a.role.rank) throw v("forbidden");
484
+ await e.delete(o.tableName, M(s, "id")), await Q(e, i, "kicked", r.id, n);
485
485
  });
486
486
  }),
487
- setRole: (e, n, r, i) => O(async () => {
488
- let a = j(e);
489
- return A(r), X(a, n, [r], async (e, o) => {
490
- let s = await J(e, a, n, "promote"), c = await K(e, a.tenantId, n, r), l = await q(e, a.tenantId, n, c), u = await W(e, _, a.tenantId, i);
491
- if (r === a.id || o.ownerId === r || u.guildId !== n || i === V(n, "owner") || l.rank <= s.role.rank || Number(u.rank) <= s.role.rank) throw t("forbidden");
492
- let d = await e.update(g.tableName, M(c, "id"), { roleId: i });
493
- if (!d) throw t("unavailable");
494
- return await Q(e, o, "roleChanged", a.id, r, { roleId: i }), L(d);
487
+ setRole: (e, t, n, r) => O(async () => {
488
+ let i = j(e);
489
+ return A(n), X(i, t, [n], async (e, a) => {
490
+ let c = await J(e, i, t, "promote"), l = await K(e, i.tenantId, t, n), u = await q(e, i.tenantId, t, l), d = await W(e, s, i.tenantId, r);
491
+ if (n === i.id || a.ownerId === n || d.guildId !== t || r === V(t, "owner") || u.rank <= c.role.rank || Number(d.rank) <= c.role.rank) throw v("forbidden");
492
+ let f = await e.update(o.tableName, M(l, "id"), { roleId: r });
493
+ if (!f) throw v("unavailable");
494
+ return await Q(e, a, "roleChanged", i.id, n, { roleId: r }), L(f);
495
495
  });
496
496
  }),
497
- configureRole: (e, n) => O(async () => {
498
- let r = j(e);
499
- if (l(n.name, 64), A(n.roleId), n.roleId.length > 64 || !Number.isSafeInteger(n.rank) || n.rank < 1 || n.rank > 1e4 || !Number.isSafeInteger(n.permissions) || n.permissions < 0 || n.permissions > 127) throw t("invalid_input");
500
- return X(r, n.guildId, [], async (e, i) => {
501
- if (await J(e, r, n.guildId, "promote"), i.ownerId !== r.id || n.roleId === V(n.guildId, "owner")) throw t("forbidden");
502
- let o = (await U(e, _, C("id", n.roleId), 1))[0];
503
- if (o && (o.tenantId !== r.tenantId || o.guildId !== n.guildId)) throw t("forbidden");
504
- let s = Z(await U(e, _, S(C("tenantId", r.tenantId), C("guildId", n.guildId))), r.tenantId, n.guildId);
505
- if (!o && s.length >= a.maxRoles) throw t("member_limit");
506
- let l = {
507
- name: n.name,
508
- rank: n.rank,
509
- permissions: n.permissions
510
- }, u = o ? await e.update(_.tableName, n.roleId, l) : await e.insert(_.tableName, {
511
- id: n.roleId,
512
- tenantId: r.tenantId,
513
- guildId: n.guildId,
514
- ...l,
497
+ configureRole: (e, t) => O(async () => {
498
+ let n = j(e);
499
+ if (g(t.name, 64), A(t.roleId), t.roleId.length > 64 || !Number.isSafeInteger(t.rank) || t.rank < 1 || t.rank > 1e4 || !Number.isSafeInteger(t.permissions) || t.permissions < 0 || t.permissions > 127) throw v("invalid_input");
500
+ return X(n, t.guildId, [], async (e, r) => {
501
+ if (await J(e, n, t.guildId, "promote"), r.ownerId !== n.id || t.roleId === V(t.guildId, "owner")) throw v("forbidden");
502
+ let i = (await U(e, s, S("id", t.roleId), 1))[0];
503
+ if (i && (i.tenantId !== n.tenantId || i.guildId !== t.guildId)) throw v("forbidden");
504
+ let a = Z(await U(e, s, x(S("tenantId", n.tenantId), S("guildId", t.guildId))), n.tenantId, t.guildId);
505
+ if (!i && a.length >= f.maxRoles) throw v("member_limit");
506
+ let o = {
507
+ name: t.name,
508
+ rank: t.rank,
509
+ permissions: t.permissions
510
+ }, c = i ? await e.update(s.tableName, t.roleId, o) : await e.insert(s.tableName, {
511
+ id: t.roleId,
512
+ tenantId: n.tenantId,
513
+ guildId: t.guildId,
514
+ ...o,
515
515
  metadata: {}
516
516
  });
517
- if (!u) throw t("unavailable");
518
- return await Q(e, i, "roleConfigured", r.id, null, { roleId: n.roleId }), F(c, u);
517
+ if (!c) throw v("unavailable");
518
+ return await Q(e, r, "roleConfigured", n.id, null, { roleId: t.roleId }), F(h, c);
519
519
  });
520
520
  }),
521
- transferOwner: (e, n, r) => O(async () => {
522
- let i = j(e);
523
- return A(r), X(i, n, [r], async (e, n) => {
524
- if (n.ownerId !== i.id) throw t("forbidden");
525
- return ce(e, n, r);
521
+ transferOwner: (e, t, n) => O(async () => {
522
+ let r = j(e);
523
+ return A(n), X(r, t, [n], async (e, t) => {
524
+ if (t.ownerId !== r.id) throw v("forbidden");
525
+ return ce(e, t, n);
526
526
  });
527
527
  }),
528
- updateProfile: (e, n) => b.gen(function* () {
529
- let r = yield* k(() => {
530
- let r = j(e);
531
- if (!Number.isSafeInteger(n.baseVersion) || n.baseVersion < 0 || n.visibility !== void 0 && ![
528
+ updateProfile: (e, t) => y.gen(function* () {
529
+ let n = yield* k(() => {
530
+ let n = j(e);
531
+ if (!Number.isSafeInteger(t.baseVersion) || t.baseVersion < 0 || t.visibility !== void 0 && ![
532
532
  "open",
533
533
  "apply",
534
534
  "invite"
535
- ].includes(n.visibility)) throw t("invalid_input");
536
- return n.description !== void 0 && l(n.description, a.maxDescriptionLength, !0), D(n.region), D(n.language), r;
535
+ ].includes(t.visibility)) throw v("invalid_input");
536
+ return t.description !== void 0 && g(t.description, f.maxDescriptionLength, !0), D(t.region), D(t.language), n;
537
537
  });
538
- return n.description !== void 0 && (yield* $(n.description)), yield* O(() => X(r, n.guildId, [], async (e, i) => {
539
- if (await J(e, r, n.guildId, "editProfile"), i.version !== n.baseVersion) throw t("conflict");
540
- let a = await e.update(y.tableName, n.guildId, {
541
- description: n.description ?? i.description,
542
- visibility: n.visibility ?? i.visibility,
543
- region: n.region === void 0 ? i.region : D(n.region),
544
- language: n.language === void 0 ? i.language : D(n.language),
545
- version: n.baseVersion + 1
538
+ return t.description !== void 0 && (yield* $(t.description)), yield* O(() => X(n, t.guildId, [], async (e, r) => {
539
+ if (await J(e, n, t.guildId, "editProfile"), r.version !== t.baseVersion) throw v("conflict");
540
+ let i = await e.update(l.tableName, t.guildId, {
541
+ description: t.description ?? r.description,
542
+ visibility: t.visibility ?? r.visibility,
543
+ region: t.region === void 0 ? r.region : D(t.region),
544
+ language: t.language === void 0 ? r.language : D(t.language),
545
+ version: t.baseVersion + 1
546
546
  });
547
- if (!a) throw t("unavailable");
548
- return await Q(e, i, "profileChanged", r.id, null), I(a);
547
+ if (!i) throw v("unavailable");
548
+ return await Q(e, r, "profileChanged", n.id, null), I(i);
549
549
  }));
550
550
  }),
551
- announce: (e, n) => b.gen(function* () {
552
- let i = yield* k(() => {
553
- let r = j(e);
554
- if (A(n.requestId), l(n.body, a.maxAnnouncementLength), n.pinned !== void 0 && typeof n.pinned != "boolean") throw t("invalid_input");
555
- return r;
551
+ announce: (e, t) => y.gen(function* () {
552
+ let r = yield* k(() => {
553
+ let n = j(e);
554
+ if (A(t.requestId), g(t.body, f.maxAnnouncementLength), t.pinned !== void 0 && typeof t.pinned != "boolean") throw v("invalid_input");
555
+ return n;
556
556
  });
557
- return yield* $(n.body), yield* O(() => X(i, n.guildId, [], async (e, a) => {
558
- await J(e, i, n.guildId, "announce");
559
- let o = E("gann", [
560
- i.tenantId,
561
- n.guildId,
562
- i.id,
563
- n.requestId
564
- ]), c = (await U(e, f, C("id", o), 1))[0];
565
- if (c) {
566
- if (c.tenantId !== i.tenantId || c.guildId !== n.guildId || c.authorId !== i.id || c.body !== n.body || P(c.pinned) !== (n.pinned ?? !1)) throw t("conflict");
567
- return F(r, c, ["createdAt"], ["pinned"]);
557
+ return yield* $(t.body), yield* O(() => X(r, t.guildId, [], async (e, i) => {
558
+ await J(e, r, t.guildId, "announce");
559
+ let a = E("gann", [
560
+ r.tenantId,
561
+ t.guildId,
562
+ r.id,
563
+ t.requestId
564
+ ]), o = (await U(e, n, S("id", a), 1))[0];
565
+ if (o) {
566
+ if (o.tenantId !== r.tenantId || o.guildId !== t.guildId || o.authorId !== r.id || o.body !== t.body || P(o.pinned) !== (t.pinned ?? !1)) throw v("conflict");
567
+ return F(u, o, ["createdAt"], ["pinned"]);
568
568
  }
569
- let l = await e.insert(f.tableName, {
570
- id: o,
571
- tenantId: i.tenantId,
572
- guildId: n.guildId,
573
- authorId: i.id,
574
- body: n.body,
575
- pinned: n.pinned ?? !1,
576
- createdAt: new Date(s()),
569
+ let s = await e.insert(n.tableName, {
570
+ id: a,
571
+ tenantId: r.tenantId,
572
+ guildId: t.guildId,
573
+ authorId: r.id,
574
+ body: t.body,
575
+ pinned: t.pinned ?? !1,
576
+ createdAt: new Date(m()),
577
577
  metadata: {}
578
578
  });
579
- return await Q(e, a, "announced", i.id, null, { announcementId: o }, n.requestId), F(r, l, ["createdAt"], ["pinned"]);
579
+ return await Q(e, i, "announced", r.id, null, { announcementId: a }, t.requestId), F(u, s, ["createdAt"], ["pinned"]);
580
580
  }));
581
581
  }),
582
582
  announcements: (e, t) => O(async () => {
583
- let n = j(e);
584
- return await G(i, n.tenantId, t), await K(i, n.tenantId, t, n.id), Z(await U(i, f, S(C("tenantId", n.tenantId), C("guildId", t)), a.pageSize), n.tenantId, t).map((e) => F(r, e, ["createdAt"], ["pinned"]));
583
+ let r = j(e);
584
+ return await G(d, r.tenantId, t), await K(d, r.tenantId, t, r.id), Z(await U(d, n, x(S("tenantId", r.tenantId), S("guildId", t)), f.pageSize), r.tenantId, t).map((e) => F(u, e, ["createdAt"], ["pinned"]));
585
585
  }),
586
586
  log: (e, t) => O(async () => {
587
587
  let n = j(e);
588
- return await G(i, n.tenantId, t), await K(i, n.tenantId, t, n.id), Z(await U(i, h, S(C("tenantId", n.tenantId), C("guildId", t)), a.pageSize), n.tenantId, t).map((e) => F(o, e, ["at"]));
588
+ return await G(d, n.tenantId, t), await K(d, n.tenantId, t, n.id), Z(await U(d, a, x(S("tenantId", n.tenantId), S("guildId", t)), f.pageSize), n.tenantId, t).map((e) => F(p, e, ["at"]));
589
589
  })
590
- }, de = (e, n, r) => {
591
- if (A(n), e.type !== "system" && !(e.type === "serviceAccount" && e.tenantId === n && e.scopes?.includes(r))) throw t("identity_required");
592
- }, fe = async (e, n) => {
593
- if (n.tenantId === null) throw t("identity_required");
594
- A(n.tenantId), A(n.subjectId);
595
- let r = [
596
- C("ownerId", n.subjectId),
597
- C("subjectId", n.subjectId),
598
- C("id", ""),
599
- w(C("subjectId", n.subjectId), C("decidedBy", n.subjectId)),
600
- w(C("toId", n.subjectId), C("fromId", n.subjectId)),
601
- w(C("actorId", n.subjectId), C("targetId", n.subjectId)),
602
- C("authorId", n.subjectId),
603
- C("id", H(n.tenantId, n.subjectId))
604
- ], i = [
605
- (e) => e.ownerId === n.subjectId,
606
- (e) => e.subjectId === n.subjectId,
590
+ }, de = (e, t, n) => {
591
+ if (A(t), e.type !== "system" && !(e.type === "serviceAccount" && e.tenantId === t && e.scopes?.includes(n))) throw v("identity_required");
592
+ }, fe = async (e, t) => {
593
+ if (t.tenantId === null) throw v("identity_required");
594
+ A(t.tenantId), A(t.subjectId);
595
+ let n = [
596
+ S("ownerId", t.subjectId),
597
+ S("subjectId", t.subjectId),
598
+ S("id", ""),
599
+ C(S("subjectId", t.subjectId), S("decidedBy", t.subjectId)),
600
+ C(S("toId", t.subjectId), S("fromId", t.subjectId)),
601
+ C(S("actorId", t.subjectId), S("targetId", t.subjectId)),
602
+ S("authorId", t.subjectId),
603
+ S("id", H(t.tenantId, t.subjectId))
604
+ ], r = [
605
+ (e) => e.ownerId === t.subjectId,
606
+ (e) => e.subjectId === t.subjectId,
607
607
  (e) => !1,
608
- (e) => e.subjectId === n.subjectId || e.decidedBy === n.subjectId,
609
- (e) => e.toId === n.subjectId || e.fromId === n.subjectId,
610
- (e) => e.actorId === n.subjectId || e.targetId === n.subjectId,
611
- (e) => e.authorId === n.subjectId,
612
- (e) => e.id === H(n.tenantId, n.subjectId)
613
- ], o = {}, s = 0;
614
- for (let t = 0; t < v.length; t++) {
615
- let a = v[t], c = Z(await U(e, a, S(C("tenantId", n.tenantId), r[t])), n.tenantId).filter(i[t]);
616
- s += c.length, o[a.tableName] = c;
608
+ (e) => e.subjectId === t.subjectId || e.decidedBy === t.subjectId,
609
+ (e) => e.toId === t.subjectId || e.fromId === t.subjectId,
610
+ (e) => e.actorId === t.subjectId || e.targetId === t.subjectId,
611
+ (e) => e.authorId === t.subjectId,
612
+ (e) => e.id === H(t.tenantId, t.subjectId)
613
+ ], i = {}, a = 0;
614
+ for (let o = 0; o < c.length; o++) {
615
+ let s = c[o], l = Z(await U(e, s, x(S("tenantId", t.tenantId), n[o])), t.tenantId).filter(r[o]);
616
+ a += l.length, i[s.tableName] = l;
617
617
  }
618
- for (let t of o[y.tableName] ?? []) {
619
- let r = Z(await U(e, _, S(C("tenantId", n.tenantId), C("guildId", t.id))), n.tenantId, M(t, "id"));
620
- o[_.tableName] = [...o[_.tableName] ?? [], ...r], s += r.length;
618
+ for (let n of i[l.tableName] ?? []) {
619
+ let r = Z(await U(e, s, x(S("tenantId", t.tenantId), S("guildId", n.id))), t.tenantId, M(n, "id"));
620
+ i[s.tableName] = [...i[s.tableName] ?? [], ...r], a += r.length;
621
621
  }
622
- if (s > a.maxExportRows) throw t("export_limit");
623
- return o;
622
+ if (a > f.maxExportRows) throw v("export_limit");
623
+ return i;
624
624
  };
625
625
  return {
626
626
  service: ue,
627
- recordContribution: (e, n) => O(async () => {
628
- if (de(e, n.tenantId, "guilds:contributions:write"), A(n.subjectId), A(n.requestId), !Number.isSafeInteger(n.xp) || n.xp < 1 || n.xp > 1e6) throw t("invalid_input");
629
- let r = {
627
+ recordContribution: (e, t) => O(async () => {
628
+ if (de(e, t.tenantId, "guilds:contributions:write"), A(t.subjectId), A(t.requestId), !Number.isSafeInteger(t.xp) || t.xp < 1 || t.xp > 1e6) throw v("invalid_input");
629
+ let n = {
630
630
  type: "user",
631
- id: n.subjectId,
632
- tenantId: n.tenantId
631
+ id: t.subjectId,
632
+ tenantId: t.tenantId
633
633
  };
634
- return X(r, n.guildId, [], async (e, r) => {
635
- let i = E("glog", [
636
- n.tenantId,
637
- n.guildId,
634
+ return X(n, t.guildId, [], async (e, n) => {
635
+ let r = E("glog", [
636
+ t.tenantId,
637
+ t.guildId,
638
638
  "contribution",
639
- n.requestId
640
- ]), o = (await U(e, h, C("id", i), 1))[0];
641
- if (o) {
642
- let e = o.detail;
643
- if (o.tenantId !== n.tenantId || o.guildId !== n.guildId || o.targetId !== n.subjectId || e.xp !== n.xp) throw t("conflict");
644
- return I(r);
639
+ t.requestId
640
+ ]), i = (await U(e, a, S("id", r), 1))[0];
641
+ if (i) {
642
+ let e = i.detail;
643
+ if (i.tenantId !== t.tenantId || i.guildId !== t.guildId || i.targetId !== t.subjectId || e.xp !== t.xp) throw v("conflict");
644
+ return I(n);
645
645
  }
646
- let c = await K(e, n.tenantId, n.guildId, n.subjectId), l = Number(r.xp) + n.xp, u = Number(c.contribution.xp ?? 0) + n.xp;
647
- if (!Number.isSafeInteger(l) || l > 2e9 || !Number.isSafeInteger(u) || u > 2e9) throw t("invalid_input");
648
- let d = a.strategies.levelCurve({
649
- xp: l,
650
- baseMemberCap: a.baseMemberCap,
651
- maximumMemberCap: a.maximumMemberCap
646
+ let s = await K(e, t.tenantId, t.guildId, t.subjectId), c = Number(n.xp) + t.xp, u = Number(s.contribution.xp ?? 0) + t.xp;
647
+ if (!Number.isSafeInteger(c) || c > 2e9 || !Number.isSafeInteger(u) || u > 2e9) throw v("invalid_input");
648
+ let d = f.strategies.levelCurve({
649
+ xp: c,
650
+ baseMemberCap: f.baseMemberCap,
651
+ maximumMemberCap: f.maximumMemberCap
652
652
  });
653
- if (!Number.isSafeInteger(d.level) || d.level < 1 || d.level > 1e6 || !Number.isSafeInteger(d.memberCap) || d.memberCap < a.baseMemberCap || d.memberCap > a.maximumMemberCap) throw t("unavailable");
654
- let f = await e.update(y.tableName, n.guildId, {
655
- xp: l,
653
+ if (!Number.isSafeInteger(d.level) || d.level < 1 || d.level > 1e6 || !Number.isSafeInteger(d.memberCap) || d.memberCap < f.baseMemberCap || d.memberCap > f.maximumMemberCap) throw v("unavailable");
654
+ let p = await e.update(l.tableName, t.guildId, {
655
+ xp: c,
656
656
  level: d.level,
657
657
  memberCap: d.memberCap,
658
- version: Number(r.version) + 1
658
+ version: Number(n.version) + 1
659
659
  });
660
- if (!f) throw t("unavailable");
661
- return await e.update(g.tableName, M(c, "id"), {
660
+ if (!p) throw v("unavailable");
661
+ return await e.update(o.tableName, M(s, "id"), {
662
662
  contribution: {
663
- ...c.contribution,
663
+ ...s.contribution,
664
664
  xp: u
665
665
  },
666
- lastActiveAt: new Date(s())
667
- }), await Q(e, r, "contribution", null, n.subjectId, { xp: n.xp }, n.requestId), I(f);
666
+ lastActiveAt: new Date(m())
667
+ }), await Q(e, n, "contribution", null, t.subjectId, { xp: t.xp }, t.requestId), I(p);
668
668
  });
669
669
  }),
670
- inactivityProposal: (e, n) => O(async () => {
671
- de(e, n.tenantId, "guilds:inactivity:read");
672
- let r = await G(i, n.tenantId, n.guildId), o = await K(i, n.tenantId, n.guildId, M(r, "ownerId")), c = [], l = Z(await U(i, g, S(C("tenantId", n.tenantId), C("guildId", n.guildId))), n.tenantId, n.guildId);
673
- for (let e of l) e.subjectId !== r.ownerId && c.push({
670
+ inactivityProposal: (e, t) => O(async () => {
671
+ de(e, t.tenantId, "guilds:inactivity:read");
672
+ let n = await G(d, t.tenantId, t.guildId), r = await K(d, t.tenantId, t.guildId, M(n, "ownerId")), i = [], a = Z(await U(d, o, x(S("tenantId", t.tenantId), S("guildId", t.guildId))), t.tenantId, t.guildId);
673
+ for (let e of a) e.subjectId !== n.ownerId && i.push({
674
674
  subjectId: M(e, "subjectId"),
675
- rank: (await q(i, n.tenantId, n.guildId, e)).rank,
675
+ rank: (await q(d, t.tenantId, t.guildId, e)).rank,
676
676
  lastActiveAt: N(e.lastActiveAt),
677
677
  joinedAt: N(e.joinedAt)
678
678
  });
679
- let u = a.strategies.inactivityPolicy({
680
- now: s(),
681
- inactiveAfterMs: a.inactiveAfterMs,
682
- ownerLastActiveAt: N(o.lastActiveAt),
683
- members: c
679
+ let s = f.strategies.inactivityPolicy({
680
+ now: m(),
681
+ inactiveAfterMs: f.inactiveAfterMs,
682
+ ownerLastActiveAt: N(r.lastActiveAt),
683
+ members: i
684
684
  });
685
- if (u !== null && !c.some((e) => e.subjectId === u)) throw t("unavailable");
686
- return u;
685
+ if (s !== null && !i.some((e) => e.subjectId === s)) throw v("unavailable");
686
+ return s;
687
687
  }),
688
- exportSubject: (e) => O(() => i.transactional(async (t) => JSON.parse(JSON.stringify(await fe(t, e))))),
688
+ exportSubject: (e) => O(() => d.transactional(async (t) => JSON.parse(JSON.stringify(await fe(t, e))))),
689
689
  mergeSubject: (e) => O(async () => {
690
- let n = e.store, r = e.tenantId, i = e.sourceId, o = e.targetId;
691
- if (A(r), A(i), A(o), i === o) throw t("invalid_input");
692
- for (let e of [i, o]) await n.insertIgnore(d.tableName, {
693
- id: H(r, e),
694
- tenantId: r,
690
+ let s = e.store, c = e.tenantId, u = e.sourceId, d = e.targetId;
691
+ if (A(c), A(u), A(d), u === d) throw v("invalid_input");
692
+ for (let e of [u, d]) await s.insertIgnore(t.tableName, {
693
+ id: H(c, e),
694
+ tenantId: c,
695
695
  subjectId: e,
696
696
  admission: 0,
697
697
  erased: !1,
698
698
  metadata: {}
699
699
  }, { conflictColumns: ["id"] });
700
- let s = await fe(n, {
701
- tenantId: r,
702
- subjectId: i,
700
+ let p = await fe(s, {
701
+ tenantId: c,
702
+ subjectId: u,
703
703
  kind: "guest"
704
- }), c = [...s[g.tableName] ?? []].sort((e, t) => M(e, "guildId") < M(t, "guildId") ? -1 : 1);
705
- await Y(n, r, [i, o], !1, async () => {
706
- for (let e of c) if (await n.updateMany(y.tableName, { admission: 0 }, { where: C("id", M(e, "guildId")) }) !== 1) throw t("unavailable");
704
+ }), m = [...p[o.tableName] ?? []].sort((e, t) => M(e, "guildId") < M(t, "guildId") ? -1 : 1);
705
+ await Y(s, c, [u, d], !1, async () => {
706
+ for (let e of m) if (await s.updateMany(l.tableName, { admission: 0 }, { where: S("id", M(e, "guildId")) }) !== 1) throw v("unavailable");
707
707
  });
708
- let l = new Set((await U(n, g, S(C("tenantId", r), C("subjectId", o)))).map((e) => M(e, "guildId")));
709
- if (l.size + c.filter((e) => !l.has(M(e, "guildId"))).length > a.maxGuildsPerSubject) throw t("guild_limit");
710
- for (let e of c) {
711
- let t = M(e, "guildId"), a = await W(n, y, r, t);
712
- if (await n.delete(g.tableName, M(e, "id")), l.has(t)) {
713
- if (a.ownerId === i) {
714
- let i = (await U(n, g, C("id", B(r, t, o)), 1))[0];
715
- await n.update(y.tableName, t, {
716
- ownerId: o,
717
- version: Number(a.version) + 1
718
- }), i && await n.update(g.tableName, M(i, "id"), { roleId: e.roleId });
708
+ let h = new Set((await U(s, o, x(S("tenantId", c), S("subjectId", d)))).map((e) => M(e, "guildId")));
709
+ if (h.size + m.filter((e) => !h.has(M(e, "guildId"))).length > f.maxGuildsPerSubject) throw v("guild_limit");
710
+ for (let e of m) {
711
+ let t = M(e, "guildId"), n = await W(s, l, c, t);
712
+ if (await s.delete(o.tableName, M(e, "id")), h.has(t)) {
713
+ if (n.ownerId === u) {
714
+ let r = (await U(s, o, S("id", B(c, t, d)), 1))[0];
715
+ await s.update(l.tableName, t, {
716
+ ownerId: d,
717
+ version: Number(n.version) + 1
718
+ }), r && await s.update(o.tableName, M(r, "id"), { roleId: e.roleId });
719
719
  }
720
- } else await n.insert(g.tableName, {
720
+ } else await s.insert(o.tableName, {
721
721
  ...e,
722
- id: B(r, t, o),
723
- subjectId: o
724
- }), l.add(t), a.ownerId === i && await n.update(y.tableName, t, {
725
- ownerId: o,
726
- version: Number(a.version) + 1
722
+ id: B(c, t, d),
723
+ subjectId: d
724
+ }), h.add(t), n.ownerId === u && await s.update(l.tableName, t, {
725
+ ownerId: d,
726
+ version: Number(n.version) + 1
727
727
  });
728
728
  }
729
- for (let e of s[p.tableName] ?? []) e.subjectId === i && e.state === "pending" ? await n.delete(p.tableName, M(e, "id")) : await n.update(p.tableName, M(e, "id"), {
730
- subjectId: e.subjectId === i ? o : e.subjectId,
731
- decidedBy: e.decidedBy === i ? o : e.decidedBy
729
+ for (let e of p[r.tableName] ?? []) e.subjectId === u && e.state === "pending" ? await s.delete(r.tableName, M(e, "id")) : await s.update(r.tableName, M(e, "id"), {
730
+ subjectId: e.subjectId === u ? d : e.subjectId,
731
+ decidedBy: e.decidedBy === u ? d : e.decidedBy
732
732
  });
733
- for (let e of s[m.tableName] ?? []) await n.delete(m.tableName, M(e, "id"));
734
- for (let e of s[h.tableName] ?? []) await n.update(h.tableName, M(e, "id"), {
735
- actorId: e.actorId === i ? o : e.actorId,
736
- targetId: e.targetId === i ? o : e.targetId
733
+ for (let e of p[i.tableName] ?? []) await s.delete(i.tableName, M(e, "id"));
734
+ for (let e of p[a.tableName] ?? []) await s.update(a.tableName, M(e, "id"), {
735
+ actorId: e.actorId === u ? d : e.actorId,
736
+ targetId: e.targetId === u ? d : e.targetId
737
737
  });
738
- for (let e of s[f.tableName] ?? []) await n.update(f.tableName, M(e, "id"), { authorId: o });
739
- await n.update(d.tableName, H(r, i), {
738
+ for (let e of p[n.tableName] ?? []) await s.update(n.tableName, M(e, "id"), { authorId: d });
739
+ await s.update(t.tableName, H(c, u), {
740
740
  subjectId: null,
741
741
  erased: !0,
742
742
  metadata: {}
743
743
  });
744
744
  }),
745
745
  eraseSubject: (e) => O(async () => {
746
- if (e.tenantId === null) throw t("identity_required");
747
- A(e.tenantId), A(e.subjectId), await oe(e.tenantId, [e.subjectId]), await i.transactional(async (n) => {
748
- await Y(n, e.tenantId, [e.subjectId], !0);
749
- let r = await fe(n, e), i = r[g.tableName] ?? [];
750
- for (let r of [...i].sort((e, t) => M(e, "guildId") < M(t, "guildId") ? -1 : 1)) {
751
- let i = M(r, "guildId");
752
- if (await n.updateMany(y.tableName, { admission: 0 }, { where: C("id", i) }) !== 1) throw t("unavailable");
753
- let a = await G(n, e.tenantId, i);
754
- if (await le(n, a, e.subjectId, !0), a.ownerId === e.subjectId) {
755
- let t = await W(n, y, e.tenantId, i);
756
- await n.update(y.tableName, i, {
757
- name: t.ownerId === null ? "" : "Guild " + T(i).slice(0, 12),
758
- nameKey: T(["privacy", i]),
746
+ if (e.tenantId === null) throw v("identity_required");
747
+ A(e.tenantId), A(e.subjectId), await oe(e.tenantId, [e.subjectId]), await d.transactional(async (c) => {
748
+ await Y(c, e.tenantId, [e.subjectId], !0);
749
+ let u = await fe(c, e), d = u[o.tableName] ?? [];
750
+ for (let t of [...d].sort((e, t) => M(e, "guildId") < M(t, "guildId") ? -1 : 1)) {
751
+ let n = M(t, "guildId");
752
+ if (await c.updateMany(l.tableName, { admission: 0 }, { where: S("id", n) }) !== 1) throw v("unavailable");
753
+ let r = await G(c, e.tenantId, n);
754
+ if (await le(c, r, e.subjectId, !0), r.ownerId === e.subjectId) {
755
+ let t = await W(c, l, e.tenantId, n);
756
+ await c.update(l.tableName, n, {
757
+ name: t.ownerId === null ? "" : "Guild " + T(n).slice(0, 12),
758
+ nameKey: T(["privacy", n]),
759
759
  description: "",
760
760
  emblem: null,
761
761
  metadata: {}
762
762
  });
763
763
  }
764
764
  }
765
- for (let t of r[p.tableName] ?? []) t.subjectId === e.subjectId ? await n.delete(p.tableName, M(t, "id")) : await n.update(p.tableName, M(t, "id"), {
765
+ for (let t of u[r.tableName] ?? []) t.subjectId === e.subjectId ? await c.delete(r.tableName, M(t, "id")) : await c.update(r.tableName, M(t, "id"), {
766
766
  decidedBy: null,
767
767
  metadata: {}
768
768
  });
769
- for (let e of r[m.tableName] ?? []) await n.delete(m.tableName, M(e, "id"));
770
- for (let t of r[h.tableName] ?? []) await n.update(h.tableName, M(t, "id"), {
769
+ for (let e of u[i.tableName] ?? []) await c.delete(i.tableName, M(e, "id"));
770
+ for (let t of u[a.tableName] ?? []) await c.update(a.tableName, M(t, "id"), {
771
771
  actorId: t.actorId === e.subjectId ? null : t.actorId,
772
772
  targetId: t.targetId === e.subjectId ? null : t.targetId,
773
773
  detail: {}
774
774
  });
775
- for (let e of r[f.tableName] ?? []) await n.update(f.tableName, M(e, "id"), {
775
+ for (let e of u[n.tableName] ?? []) await c.update(n.tableName, M(e, "id"), {
776
776
  authorId: null,
777
777
  body: "",
778
778
  metadata: {}
779
779
  });
780
- for (let e of r[_.tableName] ?? []) await n.update(_.tableName, M(e, "id"), { metadata: {} });
781
- await n.update(d.tableName, H(e.tenantId, e.subjectId), {
780
+ for (let e of u[s.tableName] ?? []) await c.update(s.tableName, M(e, "id"), { metadata: {} });
781
+ await c.update(t.tableName, H(e.tenantId, e.subjectId), {
782
782
  subjectId: null,
783
783
  erased: !0,
784
784
  metadata: {}