@voltro/plugin-guilds 0.0.0-stage → 0.88.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/CHANGELOG.md +24492 -0
- package/LICENSE +61 -0
- package/README.md +165 -2
- package/SECURITY.md +56 -0
- package/THIRD-PARTY-NOTICES.md +9063 -0
- package/dist/components.js +395 -0
- package/dist/contract.js +113 -0
- package/dist/entities.js +115 -0
- package/dist/errors.d.ts +13 -0
- package/dist/errors.js +19 -0
- package/dist/eventProducer.d.ts +8 -0
- package/dist/eventProducer.js +19 -0
- package/dist/events.d.ts +15 -0
- package/dist/events.js +13 -0
- package/dist/guild-app/events/guilds.changed.event.ts +1 -0
- package/dist/guild-app/subscribers/guilds.log.subscribe.ts +3 -0
- package/dist/index.d.ts +606 -0
- package/dist/index.js +108 -0
- package/dist/inspect.js +27 -0
- package/dist/port.d.ts +25 -0
- package/dist/port.js +4 -0
- package/dist/rpc.d.ts +355 -0
- package/dist/rpc.js +279 -0
- package/dist/rpcRoutes.js +93 -0
- package/dist/service.js +733 -0
- package/dist/strategies.d.ts +111 -0
- package/dist/strategies.js +50 -0
- package/dist/testing.d.ts +104 -0
- package/dist/testing.js +76 -0
- package/dist/web.d.ts +365 -0
- package/dist/web.js +7 -0
- package/package.json +90 -4
package/dist/service.js
ADDED
|
@@ -0,0 +1,733 @@
|
|
|
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";
|
|
9
|
+
// 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
|
+
try: e,
|
|
12
|
+
catch: D
|
|
13
|
+
}), k = (e) => y.try({
|
|
14
|
+
try: e,
|
|
15
|
+
catch: D
|
|
16
|
+
}), A = (e) => {
|
|
17
|
+
if (typeof e != "string" || !e.trim() || e.length > 256 || e.includes("\0") || e === "~") throw v("invalid_input");
|
|
18
|
+
}, j = (e) => {
|
|
19
|
+
if (e.type !== "user") throw v("identity_required");
|
|
20
|
+
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;
|
|
25
|
+
}, 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;
|
|
29
|
+
}, P = (e) => e === !0 || e === 1, F = (e, t, n = [], r = []) => {
|
|
30
|
+
let i = { ...t };
|
|
31
|
+
for (let e of n) i[e] = i[e] === null ? null : N(i[e]);
|
|
32
|
+
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");
|
|
38
|
+
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");
|
|
41
|
+
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
|
+
}, x = (e) => {
|
|
47
|
+
if (typeof e != "string" || !/^[a-zA-Z0-9]{3,5}$/u.test(e)) throw v("invalid_input");
|
|
48
|
+
return e.toUpperCase();
|
|
49
|
+
}, D = (e) => e == null ? null : o(e, 64), B = (e, t, n) => E("gmem", [
|
|
50
|
+
e,
|
|
51
|
+
t,
|
|
52
|
+
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");
|
|
65
|
+
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,
|
|
74
|
+
permission: i
|
|
75
|
+
}) !== !0) throw v("forbidden");
|
|
76
|
+
return {
|
|
77
|
+
member: a,
|
|
78
|
+
role: o
|
|
79
|
+
};
|
|
80
|
+
}, Y = async (e, n) => {
|
|
81
|
+
for (let r of [...new Set(n)].sort()) {
|
|
82
|
+
A(r);
|
|
83
|
+
let n = H(e, r);
|
|
84
|
+
try {
|
|
85
|
+
await t.insertIgnore(c.tableName, {
|
|
86
|
+
id: n,
|
|
87
|
+
tenantId: e,
|
|
88
|
+
subjectId: r,
|
|
89
|
+
admission: 0,
|
|
90
|
+
erased: !1,
|
|
91
|
+
metadata: {}
|
|
92
|
+
}, { 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;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}, ae = async (e, t, n, r = !1, i = async () => {}) => {
|
|
99
|
+
let a = [...new Set(n)].map((e) => ({
|
|
100
|
+
subject: e,
|
|
101
|
+
key: H(t, e)
|
|
102
|
+
})).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");
|
|
110
|
+
}
|
|
111
|
+
}, X = async (e, n, r, i) => {
|
|
112
|
+
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");
|
|
119
|
+
return e;
|
|
120
|
+
}, Q = (e, t, n, r, a, o = {}, s = ee()) => e.insert(f.tableName, {
|
|
121
|
+
id: E("glog", [
|
|
122
|
+
t.tenantId,
|
|
123
|
+
t.id,
|
|
124
|
+
n,
|
|
125
|
+
s
|
|
126
|
+
]),
|
|
127
|
+
tenantId: t.tenantId,
|
|
128
|
+
guildId: t.id,
|
|
129
|
+
kind: n,
|
|
130
|
+
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);
|
|
139
|
+
}
|
|
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,
|
|
147
|
+
guildId: o,
|
|
148
|
+
subjectId: r,
|
|
149
|
+
roleId: V(o, "member"),
|
|
150
|
+
joinedAt: new Date(i()),
|
|
151
|
+
lastActiveAt: new Date(i()),
|
|
152
|
+
contribution: {},
|
|
153
|
+
metadata: {}
|
|
154
|
+
}));
|
|
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") });
|
|
161
|
+
}
|
|
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
|
|
166
|
+
});
|
|
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);
|
|
171
|
+
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({
|
|
174
|
+
row: t,
|
|
175
|
+
role: await q(e, a, o, t)
|
|
176
|
+
});
|
|
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
|
+
ownerId: null,
|
|
179
|
+
dissolvedAt: new Date(i()),
|
|
180
|
+
version: Number(t.version) + 1,
|
|
181
|
+
name: "",
|
|
182
|
+
description: "",
|
|
183
|
+
emblem: null,
|
|
184
|
+
nameKey: T([
|
|
185
|
+
"dissolved",
|
|
186
|
+
o,
|
|
187
|
+
"name"
|
|
188
|
+
]),
|
|
189
|
+
tagKey: T([
|
|
190
|
+
"dissolved",
|
|
191
|
+
o,
|
|
192
|
+
"tag"
|
|
193
|
+
]),
|
|
194
|
+
tag: "",
|
|
195
|
+
metadata: {}
|
|
196
|
+
});
|
|
197
|
+
}
|
|
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);
|
|
203
|
+
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
|
+
if (![
|
|
206
|
+
"open",
|
|
207
|
+
"apply",
|
|
208
|
+
"invite"
|
|
209
|
+
].includes(c)) throw v("invalid_input");
|
|
210
|
+
return {
|
|
211
|
+
who: t,
|
|
212
|
+
guildName: i,
|
|
213
|
+
guildTag: a,
|
|
214
|
+
description: s,
|
|
215
|
+
visibility: c,
|
|
216
|
+
region: D(r.region),
|
|
217
|
+
language: D(r.language)
|
|
218
|
+
};
|
|
219
|
+
});
|
|
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,
|
|
224
|
+
r.requestId
|
|
225
|
+
]), h = T([
|
|
226
|
+
e.id,
|
|
227
|
+
o,
|
|
228
|
+
s,
|
|
229
|
+
c,
|
|
230
|
+
l,
|
|
231
|
+
u,
|
|
232
|
+
d
|
|
233
|
+
]);
|
|
234
|
+
await Y(e.tenantId, [e.id]);
|
|
235
|
+
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);
|
|
242
|
+
}
|
|
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,
|
|
254
|
+
tagKey: b,
|
|
255
|
+
description: c,
|
|
256
|
+
emblem: null,
|
|
257
|
+
visibility: l,
|
|
258
|
+
minLevel: 0,
|
|
259
|
+
region: u,
|
|
260
|
+
language: d,
|
|
261
|
+
level: 1,
|
|
262
|
+
xp: 0,
|
|
263
|
+
memberCap: n.baseMemberCap,
|
|
264
|
+
createdAt: new Date(i()),
|
|
265
|
+
ownerId: e.id,
|
|
266
|
+
version: 0,
|
|
267
|
+
admission: 0,
|
|
268
|
+
creationKey: h,
|
|
269
|
+
dissolvedAt: null,
|
|
270
|
+
metadata: {}
|
|
271
|
+
});
|
|
272
|
+
for (let [n, r, i] of [
|
|
273
|
+
[
|
|
274
|
+
"owner",
|
|
275
|
+
0,
|
|
276
|
+
127
|
|
277
|
+
],
|
|
278
|
+
[
|
|
279
|
+
"officer",
|
|
280
|
+
10,
|
|
281
|
+
119
|
|
282
|
+
],
|
|
283
|
+
[
|
|
284
|
+
"member",
|
|
285
|
+
100,
|
|
286
|
+
0
|
|
287
|
+
]
|
|
288
|
+
]) await t.insert(m.tableName, {
|
|
289
|
+
id: V(f, n),
|
|
290
|
+
tenantId: e.tenantId,
|
|
291
|
+
guildId: f,
|
|
292
|
+
name: n,
|
|
293
|
+
rank: r,
|
|
294
|
+
permissions: i,
|
|
295
|
+
metadata: {}
|
|
296
|
+
});
|
|
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()),
|
|
305
|
+
contribution: {},
|
|
306
|
+
metadata: {}
|
|
307
|
+
}), await Q(t, x, "created", e.id, null, {}, r.requestId), I(x);
|
|
308
|
+
});
|
|
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;
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
}),
|
|
316
|
+
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")))));
|
|
320
|
+
}),
|
|
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));
|
|
324
|
+
}),
|
|
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"]));
|
|
328
|
+
}),
|
|
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));
|
|
336
|
+
}),
|
|
337
|
+
join: (e, t) => O(async () => {
|
|
338
|
+
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;
|
|
343
|
+
});
|
|
344
|
+
}),
|
|
345
|
+
leave: (e, t) => O(async () => {
|
|
346
|
+
let n = j(e);
|
|
347
|
+
return X(n, t, [], (e, t) => ce(e, t, n.id, !1));
|
|
348
|
+
}),
|
|
349
|
+
apply: (e, t) => y.gen(function* () {
|
|
350
|
+
let r = yield* k(() => {
|
|
351
|
+
let r = j(e);
|
|
352
|
+
return A(t.requestId), o(t.message, n.maxDescriptionLength, !0), r;
|
|
353
|
+
});
|
|
354
|
+
return yield* $(t.message), yield* O(() => X(r, t.guildId, [], async (e, a) => {
|
|
355
|
+
if (a.visibility !== "apply") throw v("forbidden");
|
|
356
|
+
let o = E("gapp", [
|
|
357
|
+
r.tenantId,
|
|
358
|
+
t.guildId,
|
|
359
|
+
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);
|
|
365
|
+
}
|
|
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, {
|
|
370
|
+
id: o,
|
|
371
|
+
tenantId: r.tenantId,
|
|
372
|
+
guildId: t.guildId,
|
|
373
|
+
subjectId: r.id,
|
|
374
|
+
message: t.message,
|
|
375
|
+
state: "pending",
|
|
376
|
+
decidedBy: null,
|
|
377
|
+
decidedAt: null,
|
|
378
|
+
createdAt: new Date(i()),
|
|
379
|
+
metadata: {}
|
|
380
|
+
}));
|
|
381
|
+
}));
|
|
382
|
+
}),
|
|
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);
|
|
386
|
+
}),
|
|
387
|
+
decideApplication: (e, n) => O(async () => {
|
|
388
|
+
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";
|
|
396
|
+
if (o.state !== "pending") {
|
|
397
|
+
if (o.state !== s) throw v("conflict");
|
|
398
|
+
return R(o);
|
|
399
|
+
}
|
|
400
|
+
n.accept && await oe(e, t, M(o, "subjectId"));
|
|
401
|
+
let c = await e.update(u.tableName, n.applicationId, {
|
|
402
|
+
state: s,
|
|
403
|
+
decidedBy: r.id,
|
|
404
|
+
decidedAt: new Date(i())
|
|
405
|
+
});
|
|
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);
|
|
408
|
+
});
|
|
409
|
+
}),
|
|
410
|
+
invite: (e, t) => y.gen(function* () {
|
|
411
|
+
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");
|
|
418
|
+
let o = E("ginv", [
|
|
419
|
+
r.tenantId,
|
|
420
|
+
t.guildId,
|
|
421
|
+
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);
|
|
428
|
+
}
|
|
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, {
|
|
433
|
+
id: o,
|
|
434
|
+
tenantId: r.tenantId,
|
|
435
|
+
guildId: t.guildId,
|
|
436
|
+
toId: t.subjectId,
|
|
437
|
+
fromId: r.id,
|
|
438
|
+
expiresAt: new Date(i() + n.inviteTtlMs),
|
|
439
|
+
state: "pending",
|
|
440
|
+
createdAt: new Date(i()),
|
|
441
|
+
metadata: {}
|
|
442
|
+
}));
|
|
443
|
+
}));
|
|
444
|
+
}),
|
|
445
|
+
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);
|
|
449
|
+
}),
|
|
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";
|
|
462
|
+
if (o.state !== "pending") {
|
|
463
|
+
if (o.state !== s) throw v("conflict");
|
|
464
|
+
return z(o);
|
|
465
|
+
}
|
|
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,
|
|
470
|
+
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);
|
|
476
|
+
}));
|
|
477
|
+
}),
|
|
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);
|
|
484
|
+
});
|
|
485
|
+
}),
|
|
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);
|
|
494
|
+
});
|
|
495
|
+
}),
|
|
496
|
+
configureRole: (e, t) => O(async () => {
|
|
497
|
+
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,
|
|
511
|
+
tenantId: r.tenantId,
|
|
512
|
+
guildId: t.guildId,
|
|
513
|
+
...c,
|
|
514
|
+
metadata: {}
|
|
515
|
+
});
|
|
516
|
+
if (!l) throw v("unavailable");
|
|
517
|
+
return await Q(e, i, "roleConfigured", r.id, null, { roleId: t.roleId }), F(a, l);
|
|
518
|
+
});
|
|
519
|
+
}),
|
|
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);
|
|
525
|
+
});
|
|
526
|
+
}),
|
|
527
|
+
updateProfile: (e, t) => y.gen(function* () {
|
|
528
|
+
let r = yield* k(() => {
|
|
529
|
+
let r = j(e);
|
|
530
|
+
if (!Number.isSafeInteger(t.baseVersion) || t.baseVersion < 0 || t.visibility !== void 0 && ![
|
|
531
|
+
"open",
|
|
532
|
+
"apply",
|
|
533
|
+
"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;
|
|
536
|
+
});
|
|
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
|
|
545
|
+
});
|
|
546
|
+
if (!i) throw v("unavailable");
|
|
547
|
+
return await Q(e, n, "profileChanged", r.id, null), I(i);
|
|
548
|
+
}));
|
|
549
|
+
}),
|
|
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;
|
|
555
|
+
});
|
|
556
|
+
return yield* $(r.body), yield* O(() => X(a, r.guildId, [], async (t, n) => {
|
|
557
|
+
await J(t, a, r.guildId, "announce");
|
|
558
|
+
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"]);
|
|
567
|
+
}
|
|
568
|
+
let c = await t.insert(l.tableName, {
|
|
569
|
+
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()),
|
|
576
|
+
metadata: {}
|
|
577
|
+
});
|
|
578
|
+
return await Q(t, n, "announced", a.id, null, { announcementId: o }, r.requestId), F(e, c, ["createdAt"], ["pinned"]);
|
|
579
|
+
}));
|
|
580
|
+
}),
|
|
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"]));
|
|
584
|
+
}),
|
|
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"]));
|
|
588
|
+
})
|
|
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);
|
|
594
|
+
let r = [
|
|
595
|
+
C("ownerId", t.subjectId),
|
|
596
|
+
C("subjectId", t.subjectId),
|
|
597
|
+
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))
|
|
603
|
+
], i = [
|
|
604
|
+
(e) => e.ownerId === t.subjectId,
|
|
605
|
+
(e) => e.subjectId === t.subjectId,
|
|
606
|
+
(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;
|
|
616
|
+
}
|
|
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;
|
|
620
|
+
}
|
|
621
|
+
if (o > n.maxExportRows) throw v("export_limit");
|
|
622
|
+
return a;
|
|
623
|
+
};
|
|
624
|
+
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");
|
|
628
|
+
let r = {
|
|
629
|
+
type: "user",
|
|
630
|
+
id: t.subjectId,
|
|
631
|
+
tenantId: t.tenantId
|
|
632
|
+
};
|
|
633
|
+
return X(r, t.guildId, [], async (e, r) => {
|
|
634
|
+
let a = E("glog", [
|
|
635
|
+
t.tenantId,
|
|
636
|
+
t.guildId,
|
|
637
|
+
"contribution",
|
|
638
|
+
t.requestId
|
|
639
|
+
]), o = (await U(e, f, C("id", a), 1))[0];
|
|
640
|
+
if (o) {
|
|
641
|
+
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
|
+
return I(r);
|
|
644
|
+
}
|
|
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
|
|
651
|
+
});
|
|
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,
|
|
657
|
+
version: Number(r.version) + 1
|
|
658
|
+
});
|
|
659
|
+
if (!d) throw v("unavailable");
|
|
660
|
+
return await e.update(p.tableName, M(s, "id"), {
|
|
661
|
+
contribution: {
|
|
662
|
+
...s.contribution,
|
|
663
|
+
xp: l
|
|
664
|
+
},
|
|
665
|
+
lastActiveAt: new Date(i())
|
|
666
|
+
}), await Q(e, r, "contribution", null, t.subjectId, { xp: t.xp }, t.requestId), I(d);
|
|
667
|
+
});
|
|
668
|
+
}),
|
|
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({
|
|
673
|
+
subjectId: M(e, "subjectId"),
|
|
674
|
+
rank: (await q(t, r.tenantId, r.guildId, e)).rank,
|
|
675
|
+
lastActiveAt: N(e.lastActiveAt),
|
|
676
|
+
joinedAt: N(e.joinedAt)
|
|
677
|
+
});
|
|
678
|
+
let l = n.strategies.inactivityPolicy({
|
|
679
|
+
now: i(),
|
|
680
|
+
inactiveAfterMs: n.inactiveAfterMs,
|
|
681
|
+
ownerLastActiveAt: N(o.lastActiveAt),
|
|
682
|
+
members: s
|
|
683
|
+
});
|
|
684
|
+
if (l !== null && !s.some((e) => e.subjectId === l)) throw v("unavailable");
|
|
685
|
+
return l;
|
|
686
|
+
}),
|
|
687
|
+
exportSubject: (e) => O(() => t.transactional(async (t) => JSON.parse(JSON.stringify(await de(t, e))))),
|
|
688
|
+
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]),
|
|
702
|
+
description: "",
|
|
703
|
+
emblem: null,
|
|
704
|
+
metadata: {}
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
}
|
|
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"), {
|
|
709
|
+
decidedBy: null,
|
|
710
|
+
metadata: {}
|
|
711
|
+
});
|
|
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,
|
|
716
|
+
detail: {}
|
|
717
|
+
});
|
|
718
|
+
for (let e of n[l.tableName] ?? []) await t.update(l.tableName, M(e, "id"), {
|
|
719
|
+
authorId: null,
|
|
720
|
+
body: "",
|
|
721
|
+
metadata: {}
|
|
722
|
+
});
|
|
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), {
|
|
725
|
+
subjectId: null,
|
|
726
|
+
erased: !0,
|
|
727
|
+
metadata: {}
|
|
728
|
+
});
|
|
729
|
+
});
|
|
730
|
+
})
|
|
731
|
+
};
|
|
732
|
+
};
|
|
733
|
+
export { B as dataStoreGuilds };
|