@voltro/plugin-comments 0.89.2 → 0.91.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 +1943 -0
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/dist/index.js +298 -298
- package/dist/web.js +4 -4
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Effect as
|
|
5
|
-
import { and as
|
|
6
|
-
import { definePlugin as
|
|
7
|
-
import { NotificationService as
|
|
1
|
+
import { BASE_NAME as e, COMMENT_THREAD_KINDS as t, commentsFeed as n, commentsRpcClientImports as r, createDescriptor as i, deleteDescriptor as a, editDescriptor as o, listDescriptor as s, markReadDescriptor as c, mentionSearchDescriptor as l, reactDescriptor as u, resolveDescriptor as d } from "./rpc.js";
|
|
2
|
+
import { CommentAccessRefused as f, CommentNotFound as p, CommentNotYours as m, CommentStatusRefused as h } from "./errors.js";
|
|
3
|
+
import { QUOTE_MAX_LENGTH as g, findQuote as _, textQuote as v } from "./quote.js";
|
|
4
|
+
import { Effect as y, Option as b } from "effect";
|
|
5
|
+
import { and as x, contains as S, eq as C, generateId as w, id as T, inSet as E, json as D, neq as O, or as k, table as A, text as j, timestamp as M } from "@voltro/database";
|
|
6
|
+
import { definePlugin as N, effectiveScopes as P, pluginInstanceName as F, publishReactivity as I } from "@voltro/protocol";
|
|
7
|
+
import { NotificationService as L } from "@voltro/plugin-notifications";
|
|
8
8
|
// src/index.ts
|
|
9
|
-
var
|
|
10
|
-
id:
|
|
11
|
-
anchor:
|
|
12
|
-
quote:
|
|
13
|
-
kind:
|
|
14
|
-
status:
|
|
15
|
-
createdBy:
|
|
16
|
-
createdAt:
|
|
17
|
-
tenantId:
|
|
18
|
-
}).index("byThreadAnchor", ["anchor", "tenantId"]),
|
|
19
|
-
id:
|
|
20
|
-
threadId:
|
|
21
|
-
body:
|
|
22
|
-
authorSubjectId:
|
|
23
|
-
mentions:
|
|
24
|
-
editedAt:
|
|
25
|
-
createdAt:
|
|
26
|
-
tenantId:
|
|
27
|
-
}).index("byCommentThread", ["threadId"]),
|
|
28
|
-
id:
|
|
29
|
-
threadId:
|
|
30
|
-
fromStatus:
|
|
31
|
-
toStatus:
|
|
32
|
-
actor:
|
|
33
|
-
reason:
|
|
34
|
-
at:
|
|
35
|
-
tenantId:
|
|
36
|
-
}).index("byThreadEvents", ["threadId"]),
|
|
37
|
-
id:
|
|
38
|
-
commentId:
|
|
39
|
-
subjectId:
|
|
40
|
-
emoji:
|
|
9
|
+
var R = A("_voltro_comment_threads", {
|
|
10
|
+
id: T({ prefix: "cmtthr" }),
|
|
11
|
+
anchor: j(),
|
|
12
|
+
quote: D().nullable(),
|
|
13
|
+
kind: j().default("discussion"),
|
|
14
|
+
status: j().default("open"),
|
|
15
|
+
createdBy: j(),
|
|
16
|
+
createdAt: M().default("now"),
|
|
17
|
+
tenantId: j().nullable()
|
|
18
|
+
}).index("byThreadAnchor", ["anchor", "tenantId"]), z = A("_voltro_comments", {
|
|
19
|
+
id: T({ prefix: "cmt" }),
|
|
20
|
+
threadId: j(),
|
|
21
|
+
body: j(),
|
|
22
|
+
authorSubjectId: j(),
|
|
23
|
+
mentions: D(),
|
|
24
|
+
editedAt: M().nullable(),
|
|
25
|
+
createdAt: M().default("now"),
|
|
26
|
+
tenantId: j().nullable()
|
|
27
|
+
}).index("byCommentThread", ["threadId"]), B = A("_voltro_comment_thread_events", {
|
|
28
|
+
id: T({ prefix: "cmtevt" }),
|
|
29
|
+
threadId: j(),
|
|
30
|
+
fromStatus: j().nullable(),
|
|
31
|
+
toStatus: j(),
|
|
32
|
+
actor: j(),
|
|
33
|
+
reason: j().nullable(),
|
|
34
|
+
at: M().default("now"),
|
|
35
|
+
tenantId: j().nullable()
|
|
36
|
+
}).index("byThreadEvents", ["threadId"]), V = A("_voltro_comment_reactions", {
|
|
37
|
+
id: T({ prefix: "cmtrx" }),
|
|
38
|
+
commentId: j(),
|
|
39
|
+
subjectId: j(),
|
|
40
|
+
emoji: j()
|
|
41
41
|
}).unique("byReactionIdentity", [
|
|
42
42
|
"commentId",
|
|
43
43
|
"subjectId",
|
|
44
44
|
"emoji"
|
|
45
|
-
]).index("byReactionComment", ["commentId"]),
|
|
46
|
-
id:
|
|
47
|
-
threadId:
|
|
48
|
-
subjectId:
|
|
49
|
-
lastReadAt:
|
|
50
|
-
}).unique("byReadThreadSubject", ["threadId", "subjectId"]),
|
|
45
|
+
]).index("byReactionComment", ["commentId"]), H = A("_voltro_comment_reads", {
|
|
46
|
+
id: T({ prefix: "cmtread" }),
|
|
47
|
+
threadId: j(),
|
|
48
|
+
subjectId: j(),
|
|
49
|
+
lastReadAt: M()
|
|
50
|
+
}).unique("byReadThreadSubject", ["threadId", "subjectId"]), U = e, W = (e) => {
|
|
51
51
|
let t = e.request.subject ?? {};
|
|
52
52
|
return {
|
|
53
53
|
id: t.id ?? null,
|
|
54
54
|
tenantId: t.tenantId ?? null,
|
|
55
|
-
scopes:
|
|
55
|
+
scopes: P(t)
|
|
56
56
|
};
|
|
57
|
-
},
|
|
58
|
-
let
|
|
59
|
-
base:
|
|
60
|
-
alias:
|
|
61
|
-
instance:
|
|
62
|
-
}),
|
|
57
|
+
}, G = (e = {}) => {
|
|
58
|
+
let g = F({
|
|
59
|
+
base: U,
|
|
60
|
+
alias: e.alias,
|
|
61
|
+
instance: e.name
|
|
62
|
+
}), _, v, T = async (e, t, n) => _ === void 0 ? [] : _.query({
|
|
63
63
|
table: e,
|
|
64
64
|
predicate: t,
|
|
65
65
|
order: [],
|
|
66
66
|
take: n,
|
|
67
67
|
skip: void 0,
|
|
68
68
|
projection: void 0
|
|
69
|
-
}),
|
|
69
|
+
}), D = async (e, t, n, r) => {
|
|
70
70
|
let i = [], a = [...new Set(n)];
|
|
71
71
|
for (let n = 0; n < a.length; n += 500) {
|
|
72
|
-
let o =
|
|
73
|
-
i.push(...await
|
|
72
|
+
let o = E(t, a.slice(n, n + 500));
|
|
73
|
+
i.push(...await T(e, r === void 0 ? o : x(o, r)));
|
|
74
74
|
}
|
|
75
75
|
return i;
|
|
76
|
-
},
|
|
76
|
+
}, A = (e, t) => {
|
|
77
77
|
let n = /* @__PURE__ */ new Map();
|
|
78
78
|
for (let r of e) {
|
|
79
79
|
let e = String(r[t]), i = n.get(e);
|
|
80
80
|
i === void 0 ? n.set(e, [r]) : i.push(r);
|
|
81
81
|
}
|
|
82
82
|
return n;
|
|
83
|
-
},
|
|
84
|
-
|
|
85
|
-
},
|
|
86
|
-
let r =
|
|
87
|
-
return
|
|
83
|
+
}, j = () => {
|
|
84
|
+
I(v, n);
|
|
85
|
+
}, M = (t, n) => y.gen(function* () {
|
|
86
|
+
let r = W(n);
|
|
87
|
+
return e.access?.viaEntity === void 0 ? e.access?.scope === void 0 ? yield* y.fail(new f({
|
|
88
88
|
anchor: t,
|
|
89
89
|
reason: "no access rule declared — set commentsPlugin({ access: { viaEntity } }) or { access: { scope } }"
|
|
90
|
-
})) : r.scopes.includes(
|
|
90
|
+
})) : r.scopes.includes(e.access.scope) ? void 0 : yield* y.fail(new f({
|
|
91
91
|
anchor: t,
|
|
92
|
-
reason: `missing scope '${
|
|
93
|
-
})) : (yield*
|
|
92
|
+
reason: `missing scope '${e.access.scope}'`
|
|
93
|
+
})) : (yield* y.promise(async () => {
|
|
94
94
|
try {
|
|
95
|
-
return await
|
|
95
|
+
return await e.access.viaEntity({
|
|
96
96
|
anchor: t,
|
|
97
97
|
subject: r,
|
|
98
|
-
store:
|
|
98
|
+
store: _
|
|
99
99
|
});
|
|
100
100
|
} catch {
|
|
101
101
|
return !1;
|
|
102
102
|
}
|
|
103
|
-
})) ? void 0 : yield*
|
|
103
|
+
})) ? void 0 : yield* y.fail(new f({
|
|
104
104
|
anchor: t,
|
|
105
105
|
reason: "the anchored entity is not readable by this caller (or no longer available)"
|
|
106
106
|
}));
|
|
107
|
-
}),
|
|
107
|
+
}), P = async (e) => (await T("_voltro_comment_threads", C("id", e), 1))[0], G = (e) => ({
|
|
108
108
|
id: String(e.id),
|
|
109
109
|
anchor: String(e.anchor),
|
|
110
|
-
kind:
|
|
110
|
+
kind: t.includes(String(e.kind)) ? e.kind : "discussion",
|
|
111
111
|
status: e.status === "resolved" ? "resolved" : "open",
|
|
112
112
|
createdBy: String(e.createdBy)
|
|
113
|
-
}),
|
|
114
|
-
thread:
|
|
115
|
-
subject:
|
|
116
|
-
}),
|
|
117
|
-
let n = await
|
|
118
|
-
return n !== void 0 &&
|
|
119
|
-
},
|
|
113
|
+
}), K = (t, n) => e.visibleTo === void 0 || e.visibleTo({
|
|
114
|
+
thread: G(t),
|
|
115
|
+
subject: W(n)
|
|
116
|
+
}), q = async (e, t) => {
|
|
117
|
+
let n = await P(e);
|
|
118
|
+
return n !== void 0 && K(n, t) ? n : void 0;
|
|
119
|
+
}, J = async (e, t) => {
|
|
120
120
|
await e.insert("_voltro_comment_thread_events", {
|
|
121
|
-
id:
|
|
121
|
+
id: w({
|
|
122
122
|
kind: "typeid",
|
|
123
123
|
prefix: "cmtevt"
|
|
124
124
|
}, "_voltro_comment_thread_events"),
|
|
@@ -130,44 +130,44 @@ var L = k("_voltro_comment_threads", {
|
|
|
130
130
|
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
131
131
|
tenantId: t.tenantId
|
|
132
132
|
});
|
|
133
|
-
},
|
|
134
|
-
if (
|
|
135
|
-
let
|
|
136
|
-
if (
|
|
137
|
-
else for (let
|
|
138
|
-
to:
|
|
139
|
-
category:
|
|
133
|
+
}, Y = (e) => e instanceof Date ? e.toISOString() : typeof e == "string" ? e : "", X = (t) => y.gen(function* () {
|
|
134
|
+
if (t.mentions.length === 0) return;
|
|
135
|
+
let n = yield* y.serviceOption(L);
|
|
136
|
+
if (b.isNone(n)) yield* y.logInfo("comments: mention recorded without notification — @voltro/plugin-notifications is not configured");
|
|
137
|
+
else for (let r of t.mentions) r !== t.author && (yield* y.promise(() => n.value.send({
|
|
138
|
+
to: r,
|
|
139
|
+
category: e.mentionCategory ?? "mention",
|
|
140
140
|
title: "You were mentioned",
|
|
141
|
-
body:
|
|
141
|
+
body: t.body.length > 200 ? `${t.body.slice(0, 200)}…` : t.body,
|
|
142
142
|
data: {
|
|
143
|
-
anchor:
|
|
144
|
-
threadId:
|
|
143
|
+
anchor: t.anchor,
|
|
144
|
+
threadId: t.threadId
|
|
145
145
|
},
|
|
146
|
-
tenantId:
|
|
146
|
+
tenantId: t.tenantId
|
|
147
147
|
}).then(() => void 0).catch(() => void 0)));
|
|
148
|
-
}),
|
|
149
|
-
if (
|
|
150
|
-
let
|
|
151
|
-
for (let
|
|
152
|
-
let
|
|
153
|
-
query:
|
|
154
|
-
subject:
|
|
155
|
-
}).catch(() => [])).find((e) => e.subjectId ===
|
|
156
|
-
|
|
148
|
+
}), Z = async (t, n) => {
|
|
149
|
+
if (t.length === 0 || e.resolveMentions === void 0) return [];
|
|
150
|
+
let r = [];
|
|
151
|
+
for (let i of [...new Set(t)].slice(0, 20)) {
|
|
152
|
+
let t = (await e.resolveMentions({
|
|
153
|
+
query: i,
|
|
154
|
+
subject: n
|
|
155
|
+
}).catch(() => [])).find((e) => e.subjectId === i);
|
|
156
|
+
t !== void 0 && (e.crossTenant === !0 || t.tenantId === void 0 || t.tenantId === null || t.tenantId === n.tenantId) && r.push(i);
|
|
157
157
|
}
|
|
158
|
-
return
|
|
159
|
-
},
|
|
160
|
-
let { tenantId: n, id: r } =
|
|
158
|
+
return r;
|
|
159
|
+
}, Q = async (e, t) => {
|
|
160
|
+
let { tenantId: n, id: r } = W(t), i = (await T("_voltro_comment_threads", x(C("anchor", e), C("tenantId", n)))).filter((e) => K(e, t));
|
|
161
161
|
if (i.length === 0) return [];
|
|
162
162
|
let a = i.map((e) => String(e.id)), [o, s, c] = await Promise.all([
|
|
163
|
-
|
|
164
|
-
r === null ? Promise.resolve([]) :
|
|
165
|
-
|
|
166
|
-
]), l =
|
|
163
|
+
D("_voltro_comments", "threadId", a),
|
|
164
|
+
r === null ? Promise.resolve([]) : D("_voltro_comment_reads", "threadId", a, C("subjectId", r)),
|
|
165
|
+
D("_voltro_comment_thread_events", "threadId", a)
|
|
166
|
+
]), l = A(o, "threadId"), u = A(s, "threadId"), d = A(c, "threadId"), f = A(await D("_voltro_comment_reactions", "commentId", o.map((e) => String(e.id))), "commentId"), p = [];
|
|
167
167
|
for (let e of i) {
|
|
168
168
|
let t = l.get(String(e.id)) ?? [];
|
|
169
|
-
t.sort((e, t) =>
|
|
170
|
-
let n = u.get(String(e.id)) ?? [], i = n[0] ?
|
|
169
|
+
t.sort((e, t) => Y(e.createdAt) < Y(t.createdAt) ? -1 : 1);
|
|
170
|
+
let n = u.get(String(e.id)) ?? [], i = n[0] ? Y(n[0].lastReadAt) : "", a = [];
|
|
171
171
|
for (let e of t) {
|
|
172
172
|
let t = f.get(String(e.id)) ?? [], n = /* @__PURE__ */ new Map();
|
|
173
173
|
for (let e of t) {
|
|
@@ -183,8 +183,8 @@ var L = k("_voltro_comment_threads", {
|
|
|
183
183
|
body: String(e.body),
|
|
184
184
|
authorSubjectId: String(e.authorSubjectId),
|
|
185
185
|
mentions: e.mentions ?? [],
|
|
186
|
-
editedAt: e.editedAt == null ? null :
|
|
187
|
-
createdAt:
|
|
186
|
+
editedAt: e.editedAt == null ? null : Y(e.editedAt),
|
|
187
|
+
createdAt: Y(e.createdAt),
|
|
188
188
|
reactions: [...n.entries()].map(([e, t]) => ({
|
|
189
189
|
emoji: e,
|
|
190
190
|
count: t.count,
|
|
@@ -193,8 +193,8 @@ var L = k("_voltro_comment_threads", {
|
|
|
193
193
|
});
|
|
194
194
|
}
|
|
195
195
|
let o = d.get(String(e.id)) ?? [];
|
|
196
|
-
o.sort((e, t) =>
|
|
197
|
-
let s =
|
|
196
|
+
o.sort((e, t) => Y(e.at) < Y(t.at) ? -1 : Y(e.at) > Y(t.at) ? 1 : String(e.id) < String(t.id) ? -1 : 1);
|
|
197
|
+
let s = G(e);
|
|
198
198
|
p.push({
|
|
199
199
|
id: s.id,
|
|
200
200
|
anchor: s.anchor,
|
|
@@ -202,207 +202,207 @@ var L = k("_voltro_comment_threads", {
|
|
|
202
202
|
quote: e.quote ?? null,
|
|
203
203
|
status: s.status,
|
|
204
204
|
createdBy: String(e.createdBy),
|
|
205
|
-
createdAt:
|
|
205
|
+
createdAt: Y(e.createdAt),
|
|
206
206
|
comments: a,
|
|
207
207
|
unreadCount: a.filter((e) => String(e.authorSubjectId) !== r && String(e.createdAt) > i).length,
|
|
208
208
|
history: o.map((e) => ({
|
|
209
209
|
from: e.fromStatus === "open" || e.fromStatus === "resolved" ? e.fromStatus : null,
|
|
210
210
|
to: e.toStatus === "resolved" ? "resolved" : "open",
|
|
211
211
|
by: String(e.actor),
|
|
212
|
-
at:
|
|
212
|
+
at: Y(e.at),
|
|
213
213
|
reason: e.reason == null ? null : String(e.reason)
|
|
214
214
|
}))
|
|
215
215
|
});
|
|
216
216
|
}
|
|
217
217
|
return p.sort((e, t) => String(e.createdAt) < String(t.createdAt) ? -1 : 1), p;
|
|
218
|
-
},
|
|
218
|
+
}, ee = [
|
|
219
219
|
{
|
|
220
|
-
...
|
|
220
|
+
...s,
|
|
221
221
|
description: "Threads + comments + reactions + unread for one anchor, live.",
|
|
222
|
-
execute: (e, t) =>
|
|
222
|
+
execute: (e, t) => y.gen(function* () {
|
|
223
223
|
let { anchor: n } = e;
|
|
224
|
-
return yield*
|
|
224
|
+
return yield* M(n, t), yield* y.promise(() => Q(n, t));
|
|
225
225
|
})
|
|
226
226
|
},
|
|
227
227
|
{
|
|
228
|
-
...
|
|
228
|
+
...i,
|
|
229
229
|
description: "Comment on an anchor — a reply into a thread, or a new thread.",
|
|
230
|
-
execute: (
|
|
231
|
-
let
|
|
232
|
-
yield*
|
|
233
|
-
let
|
|
234
|
-
if (
|
|
235
|
-
let
|
|
236
|
-
if (
|
|
237
|
-
let e = yield*
|
|
238
|
-
if (e === void 0 || String(e.anchor) !==
|
|
230
|
+
execute: (e, t) => y.gen(function* () {
|
|
231
|
+
let n = e;
|
|
232
|
+
yield* M(n.anchor, t);
|
|
233
|
+
let r = W(t), i = r.id ?? "anonymous", a = _;
|
|
234
|
+
if (a === void 0) return yield* y.fail(new p({ id: n.anchor }));
|
|
235
|
+
let o = n.threadId;
|
|
236
|
+
if (o !== void 0) {
|
|
237
|
+
let e = yield* y.promise(() => q(o, t));
|
|
238
|
+
if (e === void 0 || String(e.anchor) !== n.anchor) return yield* y.fail(new p({ id: o }));
|
|
239
239
|
} else {
|
|
240
|
-
let
|
|
240
|
+
let e = w({
|
|
241
241
|
kind: "typeid",
|
|
242
242
|
prefix: "cmtthr"
|
|
243
243
|
}, "_voltro_comment_threads");
|
|
244
|
-
|
|
245
|
-
let
|
|
246
|
-
if (!
|
|
247
|
-
id:
|
|
248
|
-
anchor:
|
|
249
|
-
kind:
|
|
244
|
+
o = e;
|
|
245
|
+
let s = n.kind ?? "discussion";
|
|
246
|
+
if (!K({
|
|
247
|
+
id: e,
|
|
248
|
+
anchor: n.anchor,
|
|
249
|
+
kind: s,
|
|
250
250
|
status: "open",
|
|
251
|
-
createdBy:
|
|
252
|
-
},
|
|
253
|
-
anchor:
|
|
254
|
-
reason: `a ${
|
|
251
|
+
createdBy: i
|
|
252
|
+
}, t)) return yield* y.fail(new f({
|
|
253
|
+
anchor: n.anchor,
|
|
254
|
+
reason: `a ${s} thread here would not be visible to its author`
|
|
255
255
|
}));
|
|
256
|
-
yield*
|
|
257
|
-
await
|
|
258
|
-
id:
|
|
259
|
-
anchor:
|
|
260
|
-
quote:
|
|
261
|
-
kind:
|
|
256
|
+
yield* y.promise(async () => {
|
|
257
|
+
await a.insert("_voltro_comment_threads", {
|
|
258
|
+
id: e,
|
|
259
|
+
anchor: n.anchor,
|
|
260
|
+
quote: n.quote ?? null,
|
|
261
|
+
kind: s,
|
|
262
262
|
status: "open",
|
|
263
|
-
createdBy:
|
|
263
|
+
createdBy: i,
|
|
264
264
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
265
|
-
tenantId:
|
|
266
|
-
}), await
|
|
267
|
-
threadId:
|
|
265
|
+
tenantId: r.tenantId
|
|
266
|
+
}), await J(a, {
|
|
267
|
+
threadId: e,
|
|
268
268
|
from: null,
|
|
269
269
|
to: "open",
|
|
270
|
-
actor:
|
|
270
|
+
actor: i,
|
|
271
271
|
reason: null,
|
|
272
|
-
tenantId:
|
|
272
|
+
tenantId: r.tenantId
|
|
273
273
|
});
|
|
274
274
|
});
|
|
275
275
|
}
|
|
276
|
-
let
|
|
276
|
+
let s = yield* y.promise(() => Z(n.mentions ?? [], r)), c = w({
|
|
277
277
|
kind: "typeid",
|
|
278
278
|
prefix: "cmt"
|
|
279
279
|
}, "_voltro_comments");
|
|
280
|
-
return yield*
|
|
281
|
-
id:
|
|
282
|
-
threadId:
|
|
283
|
-
body:
|
|
284
|
-
authorSubjectId:
|
|
285
|
-
mentions:
|
|
280
|
+
return yield* y.promise(() => a.insert("_voltro_comments", {
|
|
281
|
+
id: c,
|
|
282
|
+
threadId: o,
|
|
283
|
+
body: n.body,
|
|
284
|
+
authorSubjectId: i,
|
|
285
|
+
mentions: s,
|
|
286
286
|
editedAt: null,
|
|
287
287
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
288
|
-
tenantId:
|
|
289
|
-
})),
|
|
290
|
-
mentions:
|
|
291
|
-
author:
|
|
292
|
-
anchor:
|
|
293
|
-
threadId:
|
|
294
|
-
body:
|
|
295
|
-
tenantId:
|
|
288
|
+
tenantId: r.tenantId
|
|
289
|
+
})), j(), yield* X({
|
|
290
|
+
mentions: s,
|
|
291
|
+
author: i,
|
|
292
|
+
anchor: n.anchor,
|
|
293
|
+
threadId: o,
|
|
294
|
+
body: n.body,
|
|
295
|
+
tenantId: r.tenantId
|
|
296
296
|
}), {
|
|
297
|
-
threadId:
|
|
298
|
-
commentId:
|
|
297
|
+
threadId: o,
|
|
298
|
+
commentId: c
|
|
299
299
|
};
|
|
300
300
|
})
|
|
301
301
|
},
|
|
302
302
|
{
|
|
303
|
-
...
|
|
303
|
+
...o,
|
|
304
304
|
description: "Edit your own comment.",
|
|
305
|
-
execute: (e,
|
|
306
|
-
let
|
|
307
|
-
if (
|
|
308
|
-
let
|
|
309
|
-
return
|
|
310
|
-
body:
|
|
305
|
+
execute: (e, t) => y.gen(function* () {
|
|
306
|
+
let n = e, r = (yield* y.promise(() => T("_voltro_comments", C("id", n.commentId), 1)))[0];
|
|
307
|
+
if (r === void 0) return yield* y.fail(new p({ id: n.commentId }));
|
|
308
|
+
let i = yield* y.promise(() => q(String(r.threadId), t));
|
|
309
|
+
return i === void 0 ? yield* y.fail(new p({ id: n.commentId })) : (yield* M(String(i.anchor), t), String(r.authorSubjectId) === (W(t).id ?? "anonymous") ? (yield* y.promise(() => _.update("_voltro_comments", n.commentId, {
|
|
310
|
+
body: n.body,
|
|
311
311
|
editedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
312
|
-
})),
|
|
312
|
+
})), j(), { ok: !0 }) : yield* y.fail(new m({ id: n.commentId })));
|
|
313
313
|
})
|
|
314
314
|
},
|
|
315
315
|
{
|
|
316
|
-
...
|
|
316
|
+
...d,
|
|
317
317
|
description: "Resolve or reopen a thread.",
|
|
318
|
-
execute: (
|
|
319
|
-
let
|
|
320
|
-
if (
|
|
321
|
-
yield*
|
|
322
|
-
let
|
|
323
|
-
if (
|
|
324
|
-
let
|
|
325
|
-
if (
|
|
318
|
+
execute: (t, n) => y.gen(function* () {
|
|
319
|
+
let r = t, i = yield* y.promise(() => q(r.threadId, n));
|
|
320
|
+
if (i === void 0) return yield* y.fail(new p({ id: r.threadId }));
|
|
321
|
+
yield* M(String(i.anchor), n);
|
|
322
|
+
let a = G(i), o = r.resolved ? "resolved" : "open";
|
|
323
|
+
if (a.status === o) return { ok: !0 };
|
|
324
|
+
let s = W(n);
|
|
325
|
+
if (e.statusPolicy !== void 0 && !(yield* y.promise(async () => {
|
|
326
326
|
try {
|
|
327
|
-
return await
|
|
328
|
-
thread:
|
|
329
|
-
to:
|
|
330
|
-
subject:
|
|
331
|
-
store:
|
|
327
|
+
return await e.statusPolicy({
|
|
328
|
+
thread: a,
|
|
329
|
+
to: o,
|
|
330
|
+
subject: s,
|
|
331
|
+
store: _
|
|
332
332
|
});
|
|
333
333
|
} catch {
|
|
334
334
|
return !1;
|
|
335
335
|
}
|
|
336
|
-
}))) return yield*
|
|
337
|
-
threadId:
|
|
338
|
-
reason: `the status policy does not let this caller ${
|
|
336
|
+
}))) return yield* y.fail(new h({
|
|
337
|
+
threadId: r.threadId,
|
|
338
|
+
reason: `the status policy does not let this caller ${r.resolved ? "resolve" : "reopen"} this ${a.kind} thread`
|
|
339
339
|
}));
|
|
340
|
-
let
|
|
341
|
-
return yield*
|
|
342
|
-
await
|
|
343
|
-
threadId:
|
|
344
|
-
from:
|
|
345
|
-
to:
|
|
346
|
-
actor:
|
|
347
|
-
reason:
|
|
348
|
-
tenantId:
|
|
340
|
+
let c = r.reason?.trim() ? r.reason.trim() : null;
|
|
341
|
+
return yield* y.promise(async () => {
|
|
342
|
+
await _.update("_voltro_comment_threads", r.threadId, { status: o }), await J(_, {
|
|
343
|
+
threadId: r.threadId,
|
|
344
|
+
from: a.status,
|
|
345
|
+
to: o,
|
|
346
|
+
actor: s.id ?? "anonymous",
|
|
347
|
+
reason: c,
|
|
348
|
+
tenantId: s.tenantId
|
|
349
349
|
});
|
|
350
|
-
}),
|
|
350
|
+
}), j(), { ok: !0 };
|
|
351
351
|
})
|
|
352
352
|
},
|
|
353
353
|
{
|
|
354
|
-
...
|
|
354
|
+
...a,
|
|
355
355
|
description: "Delete your own comment (comments:moderate deletes any).",
|
|
356
|
-
execute: (e,
|
|
357
|
-
let
|
|
358
|
-
if (
|
|
359
|
-
let
|
|
360
|
-
if (
|
|
361
|
-
yield*
|
|
362
|
-
let
|
|
363
|
-
return String(
|
|
364
|
-
for (let e of await
|
|
365
|
-
await
|
|
366
|
-
}),
|
|
356
|
+
execute: (e, t) => y.gen(function* () {
|
|
357
|
+
let n = e, r = (yield* y.promise(() => T("_voltro_comments", C("id", n.commentId), 1)))[0];
|
|
358
|
+
if (r === void 0) return yield* y.fail(new p({ id: n.commentId }));
|
|
359
|
+
let i = yield* y.promise(() => q(String(r.threadId), t));
|
|
360
|
+
if (i === void 0) return yield* y.fail(new p({ id: n.commentId }));
|
|
361
|
+
yield* M(String(i.anchor), t);
|
|
362
|
+
let a = W(t);
|
|
363
|
+
return String(r.authorSubjectId) !== (a.id ?? "anonymous") && !a.scopes.includes("comments:moderate") ? yield* y.fail(new m({ id: n.commentId })) : (yield* y.promise(async () => {
|
|
364
|
+
for (let e of await T("_voltro_comment_reactions", C("commentId", n.commentId))) await _.delete("_voltro_comment_reactions", String(e.id));
|
|
365
|
+
await _.delete("_voltro_comments", n.commentId);
|
|
366
|
+
}), j(), { ok: !0 });
|
|
367
367
|
})
|
|
368
368
|
},
|
|
369
369
|
{
|
|
370
|
-
...
|
|
370
|
+
...u,
|
|
371
371
|
description: "Toggle an emoji reaction on a comment.",
|
|
372
|
-
execute: (e,
|
|
373
|
-
let
|
|
374
|
-
if (
|
|
375
|
-
let
|
|
376
|
-
if (
|
|
377
|
-
yield*
|
|
378
|
-
let
|
|
379
|
-
if (
|
|
380
|
-
let
|
|
372
|
+
execute: (e, t) => y.gen(function* () {
|
|
373
|
+
let n = e, r = (yield* y.promise(() => T("_voltro_comments", C("id", n.commentId), 1)))[0];
|
|
374
|
+
if (r === void 0) return yield* y.fail(new p({ id: n.commentId }));
|
|
375
|
+
let i = yield* y.promise(() => q(String(r.threadId), t));
|
|
376
|
+
if (i === void 0) return yield* y.fail(new p({ id: n.commentId }));
|
|
377
|
+
yield* M(String(i.anchor), t);
|
|
378
|
+
let a = W(t).id ?? "anonymous", o = (yield* y.promise(() => T("_voltro_comment_reactions", x(C("commentId", n.commentId), x(C("subjectId", a), C("emoji", n.emoji))), 1)))[0];
|
|
379
|
+
if (o !== void 0) return yield* y.promise(() => _.delete("_voltro_comment_reactions", String(o.id))), j(), { reacted: !1 };
|
|
380
|
+
let s = w({
|
|
381
381
|
kind: "typeid",
|
|
382
382
|
prefix: "cmtrx"
|
|
383
383
|
}, "_voltro_comment_reactions");
|
|
384
|
-
return yield*
|
|
385
|
-
id:
|
|
386
|
-
commentId:
|
|
387
|
-
subjectId:
|
|
388
|
-
emoji:
|
|
389
|
-
})),
|
|
384
|
+
return yield* y.promise(() => _.insert("_voltro_comment_reactions", {
|
|
385
|
+
id: s,
|
|
386
|
+
commentId: n.commentId,
|
|
387
|
+
subjectId: a,
|
|
388
|
+
emoji: n.emoji
|
|
389
|
+
})), j(), { reacted: !0 };
|
|
390
390
|
})
|
|
391
391
|
},
|
|
392
392
|
{
|
|
393
|
-
...
|
|
393
|
+
...c,
|
|
394
394
|
description: "Stamp the caller's read marker for a thread.",
|
|
395
|
-
execute: (e,
|
|
396
|
-
let
|
|
397
|
-
if ((yield*
|
|
398
|
-
let
|
|
395
|
+
execute: (e, t) => y.gen(function* () {
|
|
396
|
+
let n = e;
|
|
397
|
+
if ((yield* y.promise(() => P(n.threadId))) === void 0) return yield* y.fail(new p({ id: n.threadId }));
|
|
398
|
+
let r = W(t).id ?? "anonymous", i = w({
|
|
399
399
|
kind: "typeid",
|
|
400
400
|
prefix: "cmtread"
|
|
401
401
|
}, "_voltro_comment_reads");
|
|
402
|
-
return yield*
|
|
403
|
-
id:
|
|
404
|
-
threadId:
|
|
405
|
-
subjectId:
|
|
402
|
+
return yield* y.promise(() => _.upsert("_voltro_comment_reads", {
|
|
403
|
+
id: i,
|
|
404
|
+
threadId: n.threadId,
|
|
405
|
+
subjectId: r,
|
|
406
406
|
lastReadAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
407
407
|
}, {
|
|
408
408
|
conflictColumns: ["threadId", "subjectId"],
|
|
@@ -411,19 +411,19 @@ var L = k("_voltro_comment_threads", {
|
|
|
411
411
|
})
|
|
412
412
|
},
|
|
413
413
|
{
|
|
414
|
-
...
|
|
414
|
+
...l,
|
|
415
415
|
description: "@-mention autocomplete over the app-declared directory, tenant-filtered.",
|
|
416
|
-
execute: (
|
|
417
|
-
let { query:
|
|
418
|
-
if (
|
|
419
|
-
let
|
|
420
|
-
return (await
|
|
421
|
-
query:
|
|
416
|
+
execute: (t, n) => y.promise(async () => {
|
|
417
|
+
let { query: r } = t;
|
|
418
|
+
if (e.resolveMentions === void 0) return [];
|
|
419
|
+
let i = W(n);
|
|
420
|
+
return (await e.resolveMentions({
|
|
421
|
+
query: r,
|
|
422
422
|
subject: {
|
|
423
|
-
id:
|
|
424
|
-
tenantId:
|
|
423
|
+
id: i.id,
|
|
424
|
+
tenantId: i.tenantId
|
|
425
425
|
}
|
|
426
|
-
}).catch(() => [])).filter((
|
|
426
|
+
}).catch(() => [])).filter((t) => e.crossTenant === !0 || t.tenantId === void 0 || t.tenantId === null || t.tenantId === i.tenantId).map((e) => ({
|
|
427
427
|
subjectId: e.subjectId,
|
|
428
428
|
label: e.label
|
|
429
429
|
}));
|
|
@@ -433,29 +433,29 @@ var L = k("_voltro_comment_threads", {
|
|
|
433
433
|
kind: "json",
|
|
434
434
|
data: e
|
|
435
435
|
});
|
|
436
|
-
return
|
|
437
|
-
name:
|
|
438
|
-
baseName:
|
|
436
|
+
return N({
|
|
437
|
+
name: g,
|
|
438
|
+
baseName: U,
|
|
439
439
|
description: "Comment threads on any app entity — replies, resolve/reopen, @-mentions with notifications, reactions, unread — live over the reactive engine.",
|
|
440
440
|
permissions: ["inspect:read", "store:write"],
|
|
441
441
|
extendSchema: { tables: [
|
|
442
|
-
L,
|
|
443
|
-
z,
|
|
444
442
|
R,
|
|
445
443
|
B,
|
|
446
|
-
|
|
444
|
+
z,
|
|
445
|
+
V,
|
|
446
|
+
H
|
|
447
447
|
] },
|
|
448
|
-
routes:
|
|
449
|
-
rpcClientDescriptors:
|
|
448
|
+
routes: ee,
|
|
449
|
+
rpcClientDescriptors: r,
|
|
450
450
|
inspectEndpoints: [{
|
|
451
451
|
method: "GET",
|
|
452
452
|
path: "/threads",
|
|
453
453
|
scope: "process",
|
|
454
454
|
description: "Thread volume and searchable, paginated threads (operator surface).",
|
|
455
|
-
handler: (e) =>
|
|
455
|
+
handler: (e) => y.promise(async () => {
|
|
456
456
|
let t = new URL(e.url, "http://inspect.local").searchParams, n = t.get("threadId"), r = Number(t.get("offset") ?? 0), i = Number.isSafeInteger(r) && r >= 0 ? r : 0, a = (t.get("search") ?? "").trim().slice(0, 200);
|
|
457
457
|
if (n) {
|
|
458
|
-
let e = (await
|
|
458
|
+
let e = (await T("_voltro_comment_threads", C("id", n), 1))[0], t = C("threadId", n), [r, a] = e && _ ? await Promise.all([_.query({
|
|
459
459
|
table: "_voltro_comments",
|
|
460
460
|
predicate: t,
|
|
461
461
|
order: [{
|
|
@@ -468,7 +468,7 @@ var L = k("_voltro_comment_threads", {
|
|
|
468
468
|
take: 50,
|
|
469
469
|
skip: i,
|
|
470
470
|
projection: void 0
|
|
471
|
-
}),
|
|
471
|
+
}), _.query({
|
|
472
472
|
table: "_voltro_comments",
|
|
473
473
|
predicate: t,
|
|
474
474
|
order: [],
|
|
@@ -479,32 +479,32 @@ var L = k("_voltro_comment_threads", {
|
|
|
479
479
|
op: "count",
|
|
480
480
|
alias: "count"
|
|
481
481
|
}]
|
|
482
|
-
})]) : [[], []],
|
|
482
|
+
})]) : [[], []], o = Number(a[0]?.count ?? 0);
|
|
483
483
|
return $({
|
|
484
484
|
stats: {
|
|
485
485
|
threads: +!!e,
|
|
486
486
|
open: e && e.status !== "resolved" ? 1 : 0,
|
|
487
|
-
comments:
|
|
487
|
+
comments: o
|
|
488
488
|
},
|
|
489
489
|
recent: [],
|
|
490
490
|
detail: {
|
|
491
491
|
threadId: n,
|
|
492
492
|
found: !!e,
|
|
493
493
|
offset: i,
|
|
494
|
-
total:
|
|
494
|
+
total: o,
|
|
495
495
|
messages: r.map((e) => ({
|
|
496
496
|
id: String(e.id),
|
|
497
497
|
body: String(e.body),
|
|
498
498
|
author: String(e.authorSubjectId),
|
|
499
|
-
createdAt:
|
|
500
|
-
editedAt: e.editedAt == null ? null :
|
|
499
|
+
createdAt: Y(e.createdAt),
|
|
500
|
+
editedAt: e.editedAt == null ? null : Y(e.editedAt)
|
|
501
501
|
}))
|
|
502
502
|
}
|
|
503
503
|
});
|
|
504
504
|
}
|
|
505
|
-
if (!
|
|
506
|
-
let
|
|
507
|
-
let n = await
|
|
505
|
+
if (!_) throw Error("Comments store is not available");
|
|
506
|
+
let o = async (e, t) => {
|
|
507
|
+
let n = await _.query({
|
|
508
508
|
table: e,
|
|
509
509
|
predicate: t,
|
|
510
510
|
order: [],
|
|
@@ -517,10 +517,10 @@ var L = k("_voltro_comment_threads", {
|
|
|
517
517
|
}]
|
|
518
518
|
});
|
|
519
519
|
return Number(n[0]?.count ?? 0);
|
|
520
|
-
},
|
|
521
|
-
|
|
520
|
+
}, s = a ? k(S("anchor", a), S("id", a), S("createdBy", a)) : void 0, [c, l, u, d, f] = await Promise.all([
|
|
521
|
+
_.query({
|
|
522
522
|
table: "_voltro_comment_threads",
|
|
523
|
-
predicate:
|
|
523
|
+
predicate: s,
|
|
524
524
|
order: [{
|
|
525
525
|
column: "createdAt",
|
|
526
526
|
direction: "desc"
|
|
@@ -532,13 +532,13 @@ var L = k("_voltro_comment_threads", {
|
|
|
532
532
|
skip: i,
|
|
533
533
|
projection: void 0
|
|
534
534
|
}),
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
]),
|
|
535
|
+
o("_voltro_comment_threads"),
|
|
536
|
+
o("_voltro_comment_threads", O("status", "resolved")),
|
|
537
|
+
o("_voltro_comments"),
|
|
538
|
+
o("_voltro_comment_threads", s)
|
|
539
|
+
]), p = c.length === 0 ? [] : await _.query({
|
|
540
540
|
table: "_voltro_comments",
|
|
541
|
-
predicate:
|
|
541
|
+
predicate: E("threadId", c.map((e) => String(e.id))),
|
|
542
542
|
order: [],
|
|
543
543
|
take: void 0,
|
|
544
544
|
skip: void 0,
|
|
@@ -552,41 +552,41 @@ var L = k("_voltro_comment_threads", {
|
|
|
552
552
|
alias: "count"
|
|
553
553
|
}],
|
|
554
554
|
groupBy: ["threadId"]
|
|
555
|
-
}),
|
|
555
|
+
}), m = new Map(p.map((e) => [String(e.threadId), Number(e.count)]));
|
|
556
556
|
return $({
|
|
557
557
|
stats: {
|
|
558
|
-
threads:
|
|
559
|
-
open:
|
|
560
|
-
comments:
|
|
558
|
+
threads: l,
|
|
559
|
+
open: u,
|
|
560
|
+
comments: d
|
|
561
561
|
},
|
|
562
562
|
page: {
|
|
563
563
|
offset: i,
|
|
564
564
|
search: a,
|
|
565
|
-
total:
|
|
565
|
+
total: f,
|
|
566
566
|
pageSize: 50
|
|
567
567
|
},
|
|
568
|
-
recent:
|
|
568
|
+
recent: c.map((e) => ({
|
|
569
569
|
id: String(e.id),
|
|
570
570
|
anchor: String(e.anchor),
|
|
571
571
|
status: String(e.status),
|
|
572
572
|
createdBy: String(e.createdBy),
|
|
573
|
-
createdAt:
|
|
574
|
-
comments:
|
|
573
|
+
createdAt: Y(e.createdAt),
|
|
574
|
+
comments: m.get(String(e.id)) ?? 0
|
|
575
575
|
}))
|
|
576
576
|
});
|
|
577
577
|
})
|
|
578
578
|
}],
|
|
579
579
|
bindDataStore: (e) => {
|
|
580
|
-
|
|
580
|
+
_ = e, v = e;
|
|
581
581
|
},
|
|
582
|
-
onActivate: (
|
|
583
|
-
|
|
582
|
+
onActivate: (t) => y.sync(() => {
|
|
583
|
+
e.access?.viaEntity === void 0 && e.access?.scope === void 0 && t.logger.warn("comments: no access rule declared — EVERY read and write will be refused (fail-closed). Set commentsPlugin({ access: { viaEntity } }) or { access: { scope } }."), t.logger.info("comments active", { mentions: e.resolveMentions !== void 0 });
|
|
584
584
|
}),
|
|
585
|
-
onDeactivate: () =>
|
|
586
|
-
|
|
585
|
+
onDeactivate: () => y.sync(() => {
|
|
586
|
+
_ = void 0, v = void 0;
|
|
587
587
|
})
|
|
588
588
|
});
|
|
589
|
-
},
|
|
589
|
+
}, K = async (e, t, n = /* @__PURE__ */ new Date()) => {
|
|
590
590
|
let r = (t, n) => e.query({
|
|
591
591
|
table: t,
|
|
592
592
|
predicate: n,
|
|
@@ -598,20 +598,20 @@ var L = k("_voltro_comment_threads", {
|
|
|
598
598
|
for (let [o, s] of Object.entries(t)) {
|
|
599
599
|
if (s === void 0 || !(s >= 0)) continue;
|
|
600
600
|
let t = n.getTime() - s * 864e5;
|
|
601
|
-
for (let c of await r("_voltro_comment_threads",
|
|
602
|
-
let o = [...await r("_voltro_comment_thread_events",
|
|
601
|
+
for (let c of await r("_voltro_comment_threads", x(C("status", "resolved"), C("kind", o)))) {
|
|
602
|
+
let o = [...await r("_voltro_comment_thread_events", C("threadId", String(c.id)))], l = (e) => new Date(e.at instanceof Date ? e.at : String(e.at)).getTime();
|
|
603
603
|
o.sort((e, t) => l(e) - l(t));
|
|
604
604
|
let u = [...o].reverse().find((e) => e.toStatus === "resolved" && e.fromStatus === "open");
|
|
605
605
|
if (u === void 0 || l(u) > t) continue;
|
|
606
|
-
let d = await r("_voltro_comments",
|
|
606
|
+
let d = await r("_voltro_comments", C("threadId", String(c.id)));
|
|
607
607
|
if (d.length !== 0) {
|
|
608
608
|
for (let t of d) {
|
|
609
|
-
for (let n of await r("_voltro_comment_reactions",
|
|
609
|
+
for (let n of await r("_voltro_comment_reactions", C("commentId", String(t.id)))) await e.delete("_voltro_comment_reactions", String(n.id));
|
|
610
610
|
await e.delete("_voltro_comments", String(t.id));
|
|
611
611
|
}
|
|
612
|
-
for (let t of await r("_voltro_comment_reads",
|
|
612
|
+
for (let t of await r("_voltro_comment_reads", C("threadId", String(c.id)))) await e.delete("_voltro_comment_reads", String(t.id));
|
|
613
613
|
await e.insert("_voltro_comment_thread_events", {
|
|
614
|
-
id:
|
|
614
|
+
id: w({
|
|
615
615
|
kind: "typeid",
|
|
616
616
|
prefix: "cmtevt"
|
|
617
617
|
}, "_voltro_comment_thread_events"),
|
|
@@ -630,5 +630,5 @@ var L = k("_voltro_comment_threads", {
|
|
|
630
630
|
threads: i,
|
|
631
631
|
comments: a
|
|
632
632
|
};
|
|
633
|
-
},
|
|
634
|
-
export {
|
|
633
|
+
}, q = () => "plugin-comments";
|
|
634
|
+
export { t as COMMENT_THREAD_KINDS, f as CommentAccessRefused, p as CommentNotFound, m as CommentNotYours, h as CommentStatusRefused, g as QUOTE_MAX_LENGTH, K as applyCommentRetention, V as commentReactionsTable, H as commentReadsTable, B as commentThreadEventsTable, R as commentThreadsTable, n as commentsFeed, G as commentsPlugin, z as commentsTable, _ as findQuote, q as pluginComments, v as textQuote };
|