@voltro/plugin-guilds 0.89.1 → 0.90.0

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