@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/dist/index.js CHANGED
@@ -1,124 +1,124 @@
1
- import { CommentAccessRefused as e, CommentNotFound as t, CommentNotYours as n, CommentStatusRefused as r } from "./errors.js";
2
- import { QUOTE_MAX_LENGTH as i, findQuote as a, textQuote as o } from "./quote.js";
3
- import { BASE_NAME as s, COMMENT_THREAD_KINDS as c, commentsFeed as l, commentsRpcClientImports as u, createDescriptor as d, deleteDescriptor as f, editDescriptor as p, listDescriptor as m, markReadDescriptor as h, mentionSearchDescriptor as g, reactDescriptor as _, resolveDescriptor as ee } from "./rpc.js";
4
- import { Effect as v, Option as y } from "effect";
5
- import { and as b, contains as x, eq as S, generateId as C, id as w, inSet as T, json as E, neq as D, or as O, table as k, text as A, timestamp as j } from "@voltro/database";
6
- import { definePlugin as M, effectiveScopes as N, pluginInstanceName as P, publishReactivity as F } from "@voltro/protocol";
7
- import { NotificationService as I } from "@voltro/plugin-notifications";
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 L = k("_voltro_comment_threads", {
10
- id: w({ prefix: "cmtthr" }),
11
- anchor: A(),
12
- quote: E().nullable(),
13
- kind: A().default("discussion"),
14
- status: A().default("open"),
15
- createdBy: A(),
16
- createdAt: j().default("now"),
17
- tenantId: A().nullable()
18
- }).index("byThreadAnchor", ["anchor", "tenantId"]), R = k("_voltro_comments", {
19
- id: w({ prefix: "cmt" }),
20
- threadId: A(),
21
- body: A(),
22
- authorSubjectId: A(),
23
- mentions: E(),
24
- editedAt: j().nullable(),
25
- createdAt: j().default("now"),
26
- tenantId: A().nullable()
27
- }).index("byCommentThread", ["threadId"]), z = k("_voltro_comment_thread_events", {
28
- id: w({ prefix: "cmtevt" }),
29
- threadId: A(),
30
- fromStatus: A().nullable(),
31
- toStatus: A(),
32
- actor: A(),
33
- reason: A().nullable(),
34
- at: j().default("now"),
35
- tenantId: A().nullable()
36
- }).index("byThreadEvents", ["threadId"]), B = k("_voltro_comment_reactions", {
37
- id: w({ prefix: "cmtrx" }),
38
- commentId: A(),
39
- subjectId: A(),
40
- emoji: A()
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"]), V = k("_voltro_comment_reads", {
46
- id: w({ prefix: "cmtread" }),
47
- threadId: A(),
48
- subjectId: A(),
49
- lastReadAt: j()
50
- }).unique("byReadThreadSubject", ["threadId", "subjectId"]), H = s, U = (e) => {
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: N(t)
55
+ scopes: P(t)
56
56
  };
57
- }, W = (i = {}) => {
58
- let a = P({
59
- base: H,
60
- alias: i.alias,
61
- instance: i.name
62
- }), o, s, w = async (e, t, n) => o === void 0 ? [] : o.query({
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
- }), E = async (e, t, n, r) => {
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 = T(t, a.slice(n, n + 500));
73
- i.push(...await w(e, r === void 0 ? o : b(o, r)));
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
- }, k = (e, t) => {
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
- }, A = () => {
84
- F(s, l);
85
- }, j = (t, n) => v.gen(function* () {
86
- let r = U(n);
87
- return i.access?.viaEntity === void 0 ? i.access?.scope === void 0 ? yield* v.fail(new e({
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(i.access.scope) ? void 0 : yield* v.fail(new e({
90
+ })) : r.scopes.includes(e.access.scope) ? void 0 : yield* y.fail(new f({
91
91
  anchor: t,
92
- reason: `missing scope '${i.access.scope}'`
93
- })) : (yield* v.promise(async () => {
92
+ reason: `missing scope '${e.access.scope}'`
93
+ })) : (yield* y.promise(async () => {
94
94
  try {
95
- return await i.access.viaEntity({
95
+ return await e.access.viaEntity({
96
96
  anchor: t,
97
97
  subject: r,
98
- store: o
98
+ store: _
99
99
  });
100
100
  } catch {
101
101
  return !1;
102
102
  }
103
- })) ? void 0 : yield* v.fail(new e({
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
- }), N = async (e) => (await w("_voltro_comment_threads", S("id", e), 1))[0], W = (e) => ({
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: c.includes(String(e.kind)) ? e.kind : "discussion",
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
- }), G = (e, t) => i.visibleTo === void 0 || i.visibleTo({
114
- thread: W(e),
115
- subject: U(t)
116
- }), K = async (e, t) => {
117
- let n = await N(e);
118
- return n !== void 0 && G(n, t) ? n : void 0;
119
- }, q = async (e, t) => {
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: C({
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
- }, J = (e) => e instanceof Date ? e.toISOString() : typeof e == "string" ? e : "", Y = (e) => v.gen(function* () {
134
- if (e.mentions.length === 0) return;
135
- let t = yield* v.serviceOption(I);
136
- if (y.isNone(t)) yield* v.logInfo("comments: mention recorded without notification — @voltro/plugin-notifications is not configured");
137
- else for (let n of e.mentions) n !== e.author && (yield* v.promise(() => t.value.send({
138
- to: n,
139
- category: i.mentionCategory ?? "mention",
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: e.body.length > 200 ? `${e.body.slice(0, 200)}…` : e.body,
141
+ body: t.body.length > 200 ? `${t.body.slice(0, 200)}…` : t.body,
142
142
  data: {
143
- anchor: e.anchor,
144
- threadId: e.threadId
143
+ anchor: t.anchor,
144
+ threadId: t.threadId
145
145
  },
146
- tenantId: e.tenantId
146
+ tenantId: t.tenantId
147
147
  }).then(() => void 0).catch(() => void 0)));
148
- }), X = async (e, t) => {
149
- if (e.length === 0 || i.resolveMentions === void 0) return [];
150
- let n = [];
151
- for (let r of [...new Set(e)].slice(0, 20)) {
152
- let e = (await i.resolveMentions({
153
- query: r,
154
- subject: t
155
- }).catch(() => [])).find((e) => e.subjectId === r);
156
- e !== void 0 && (i.crossTenant === !0 || e.tenantId === void 0 || e.tenantId === null || e.tenantId === t.tenantId) && n.push(r);
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 n;
159
- }, Z = async (e, t) => {
160
- let { tenantId: n, id: r } = U(t), i = (await w("_voltro_comment_threads", b(S("anchor", e), S("tenantId", n)))).filter((e) => G(e, t));
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
- E("_voltro_comments", "threadId", a),
164
- r === null ? Promise.resolve([]) : E("_voltro_comment_reads", "threadId", a, S("subjectId", r)),
165
- E("_voltro_comment_thread_events", "threadId", a)
166
- ]), l = k(o, "threadId"), u = k(s, "threadId"), d = k(c, "threadId"), f = k(await E("_voltro_comment_reactions", "commentId", o.map((e) => String(e.id))), "commentId"), p = [];
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) => J(e.createdAt) < J(t.createdAt) ? -1 : 1);
170
- let n = u.get(String(e.id)) ?? [], i = n[0] ? J(n[0].lastReadAt) : "", a = [];
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 : J(e.editedAt),
187
- createdAt: J(e.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) => J(e.at) < J(t.at) ? -1 : J(e.at) > J(t.at) ? 1 : String(e.id) < String(t.id) ? -1 : 1);
197
- let s = W(e);
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: J(e.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: J(e.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
- }, Q = [
218
+ }, ee = [
219
219
  {
220
- ...m,
220
+ ...s,
221
221
  description: "Threads + comments + reactions + unread for one anchor, live.",
222
- execute: (e, t) => v.gen(function* () {
222
+ execute: (e, t) => y.gen(function* () {
223
223
  let { anchor: n } = e;
224
- return yield* j(n, t), yield* v.promise(() => Z(n, t));
224
+ return yield* M(n, t), yield* y.promise(() => Q(n, t));
225
225
  })
226
226
  },
227
227
  {
228
- ...d,
228
+ ...i,
229
229
  description: "Comment on an anchor — a reply into a thread, or a new thread.",
230
- execute: (n, r) => v.gen(function* () {
231
- let i = n;
232
- yield* j(i.anchor, r);
233
- let a = U(r), s = a.id ?? "anonymous", c = o;
234
- if (c === void 0) return yield* v.fail(new t({ id: i.anchor }));
235
- let l = i.threadId;
236
- if (l !== void 0) {
237
- let e = yield* v.promise(() => K(l, r));
238
- if (e === void 0 || String(e.anchor) !== i.anchor) return yield* v.fail(new t({ id: l }));
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 t = C({
240
+ let e = w({
241
241
  kind: "typeid",
242
242
  prefix: "cmtthr"
243
243
  }, "_voltro_comment_threads");
244
- l = t;
245
- let n = i.kind ?? "discussion";
246
- if (!G({
247
- id: t,
248
- anchor: i.anchor,
249
- kind: n,
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: s
252
- }, r)) return yield* v.fail(new e({
253
- anchor: i.anchor,
254
- reason: `a ${n} thread here would not be visible to its author`
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* v.promise(async () => {
257
- await c.insert("_voltro_comment_threads", {
258
- id: t,
259
- anchor: i.anchor,
260
- quote: i.quote ?? null,
261
- kind: n,
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: s,
263
+ createdBy: i,
264
264
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
265
- tenantId: a.tenantId
266
- }), await q(c, {
267
- threadId: t,
265
+ tenantId: r.tenantId
266
+ }), await J(a, {
267
+ threadId: e,
268
268
  from: null,
269
269
  to: "open",
270
- actor: s,
270
+ actor: i,
271
271
  reason: null,
272
- tenantId: a.tenantId
272
+ tenantId: r.tenantId
273
273
  });
274
274
  });
275
275
  }
276
- let u = yield* v.promise(() => X(i.mentions ?? [], a)), d = C({
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* v.promise(() => c.insert("_voltro_comments", {
281
- id: d,
282
- threadId: l,
283
- body: i.body,
284
- authorSubjectId: s,
285
- mentions: u,
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: a.tenantId
289
- })), A(), yield* Y({
290
- mentions: u,
291
- author: s,
292
- anchor: i.anchor,
293
- threadId: l,
294
- body: i.body,
295
- tenantId: a.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: l,
298
- commentId: d
297
+ threadId: o,
298
+ commentId: c
299
299
  };
300
300
  })
301
301
  },
302
302
  {
303
- ...p,
303
+ ...o,
304
304
  description: "Edit your own comment.",
305
- execute: (e, r) => v.gen(function* () {
306
- let i = e, a = (yield* v.promise(() => w("_voltro_comments", S("id", i.commentId), 1)))[0];
307
- if (a === void 0) return yield* v.fail(new t({ id: i.commentId }));
308
- let s = yield* v.promise(() => K(String(a.threadId), r));
309
- return s === void 0 ? yield* v.fail(new t({ id: i.commentId })) : (yield* j(String(s.anchor), r), String(a.authorSubjectId) === (U(r).id ?? "anonymous") ? (yield* v.promise(() => o.update("_voltro_comments", i.commentId, {
310
- body: i.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
- })), A(), { ok: !0 }) : yield* v.fail(new n({ id: i.commentId })));
312
+ })), j(), { ok: !0 }) : yield* y.fail(new m({ id: n.commentId })));
313
313
  })
314
314
  },
315
315
  {
316
- ...ee,
316
+ ...d,
317
317
  description: "Resolve or reopen a thread.",
318
- execute: (e, n) => v.gen(function* () {
319
- let a = e, s = yield* v.promise(() => K(a.threadId, n));
320
- if (s === void 0) return yield* v.fail(new t({ id: a.threadId }));
321
- yield* j(String(s.anchor), n);
322
- let c = W(s), l = a.resolved ? "resolved" : "open";
323
- if (c.status === l) return { ok: !0 };
324
- let u = U(n);
325
- if (i.statusPolicy !== void 0 && !(yield* v.promise(async () => {
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 i.statusPolicy({
328
- thread: c,
329
- to: l,
330
- subject: u,
331
- store: o
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* v.fail(new r({
337
- threadId: a.threadId,
338
- reason: `the status policy does not let this caller ${a.resolved ? "resolve" : "reopen"} this ${c.kind} thread`
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 d = a.reason?.trim() ? a.reason.trim() : null;
341
- return yield* v.promise(async () => {
342
- await o.update("_voltro_comment_threads", a.threadId, { status: l }), await q(o, {
343
- threadId: a.threadId,
344
- from: c.status,
345
- to: l,
346
- actor: u.id ?? "anonymous",
347
- reason: d,
348
- tenantId: u.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
- }), A(), { ok: !0 };
350
+ }), j(), { ok: !0 };
351
351
  })
352
352
  },
353
353
  {
354
- ...f,
354
+ ...a,
355
355
  description: "Delete your own comment (comments:moderate deletes any).",
356
- execute: (e, r) => v.gen(function* () {
357
- let i = e, a = (yield* v.promise(() => w("_voltro_comments", S("id", i.commentId), 1)))[0];
358
- if (a === void 0) return yield* v.fail(new t({ id: i.commentId }));
359
- let s = yield* v.promise(() => K(String(a.threadId), r));
360
- if (s === void 0) return yield* v.fail(new t({ id: i.commentId }));
361
- yield* j(String(s.anchor), r);
362
- let c = U(r);
363
- return String(a.authorSubjectId) !== (c.id ?? "anonymous") && !c.scopes.includes("comments:moderate") ? yield* v.fail(new n({ id: i.commentId })) : (yield* v.promise(async () => {
364
- for (let e of await w("_voltro_comment_reactions", S("commentId", i.commentId))) await o.delete("_voltro_comment_reactions", String(e.id));
365
- await o.delete("_voltro_comments", i.commentId);
366
- }), A(), { ok: !0 });
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, n) => v.gen(function* () {
373
- let r = e, i = (yield* v.promise(() => w("_voltro_comments", S("id", r.commentId), 1)))[0];
374
- if (i === void 0) return yield* v.fail(new t({ id: r.commentId }));
375
- let a = yield* v.promise(() => K(String(i.threadId), n));
376
- if (a === void 0) return yield* v.fail(new t({ id: r.commentId }));
377
- yield* j(String(a.anchor), n);
378
- let s = U(n).id ?? "anonymous", c = (yield* v.promise(() => w("_voltro_comment_reactions", b(S("commentId", r.commentId), b(S("subjectId", s), S("emoji", r.emoji))), 1)))[0];
379
- if (c !== void 0) return yield* v.promise(() => o.delete("_voltro_comment_reactions", String(c.id))), A(), { reacted: !1 };
380
- let l = C({
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* v.promise(() => o.insert("_voltro_comment_reactions", {
385
- id: l,
386
- commentId: r.commentId,
387
- subjectId: s,
388
- emoji: r.emoji
389
- })), A(), { reacted: !0 };
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
- ...h,
393
+ ...c,
394
394
  description: "Stamp the caller's read marker for a thread.",
395
- execute: (e, n) => v.gen(function* () {
396
- let r = e;
397
- if ((yield* v.promise(() => N(r.threadId))) === void 0) return yield* v.fail(new t({ id: r.threadId }));
398
- let i = U(n).id ?? "anonymous", a = C({
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* v.promise(() => o.upsert("_voltro_comment_reads", {
403
- id: a,
404
- threadId: r.threadId,
405
- subjectId: i,
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
- ...g,
414
+ ...l,
415
415
  description: "@-mention autocomplete over the app-declared directory, tenant-filtered.",
416
- execute: (e, t) => v.promise(async () => {
417
- let { query: n } = e;
418
- if (i.resolveMentions === void 0) return [];
419
- let r = U(t);
420
- return (await i.resolveMentions({
421
- query: n,
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: r.id,
424
- tenantId: r.tenantId
423
+ id: i.id,
424
+ tenantId: i.tenantId
425
425
  }
426
- }).catch(() => [])).filter((e) => i.crossTenant === !0 || e.tenantId === void 0 || e.tenantId === null || e.tenantId === r.tenantId).map((e) => ({
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 M({
437
- name: a,
438
- baseName: H,
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
- V
444
+ z,
445
+ V,
446
+ H
447
447
  ] },
448
- routes: Q,
449
- rpcClientDescriptors: u,
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) => v.promise(async () => {
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 w("_voltro_comment_threads", S("id", n), 1))[0], t = S("threadId", n), [r, a] = e && o ? await Promise.all([o.query({
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
- }), o.query({
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
- })]) : [[], []], s = Number(a[0]?.count ?? 0);
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: s
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: s,
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: J(e.createdAt),
500
- editedAt: e.editedAt == null ? null : J(e.editedAt)
499
+ createdAt: Y(e.createdAt),
500
+ editedAt: e.editedAt == null ? null : Y(e.editedAt)
501
501
  }))
502
502
  }
503
503
  });
504
504
  }
505
- if (!o) throw Error("Comments store is not available");
506
- let s = async (e, t) => {
507
- let n = await o.query({
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
- }, c = a ? O(x("anchor", a), x("id", a), x("createdBy", a)) : void 0, [l, u, d, f, p] = await Promise.all([
521
- o.query({
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: c,
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
- s("_voltro_comment_threads"),
536
- s("_voltro_comment_threads", D("status", "resolved")),
537
- s("_voltro_comments"),
538
- s("_voltro_comment_threads", c)
539
- ]), m = l.length === 0 ? [] : await o.query({
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: T("threadId", l.map((e) => String(e.id))),
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
- }), h = new Map(m.map((e) => [String(e.threadId), Number(e.count)]));
555
+ }), m = new Map(p.map((e) => [String(e.threadId), Number(e.count)]));
556
556
  return $({
557
557
  stats: {
558
- threads: u,
559
- open: d,
560
- comments: f
558
+ threads: l,
559
+ open: u,
560
+ comments: d
561
561
  },
562
562
  page: {
563
563
  offset: i,
564
564
  search: a,
565
- total: p,
565
+ total: f,
566
566
  pageSize: 50
567
567
  },
568
- recent: l.map((e) => ({
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: J(e.createdAt),
574
- comments: h.get(String(e.id)) ?? 0
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
- o = e, s = e;
580
+ _ = e, v = e;
581
581
  },
582
- onActivate: (e) => v.sync(() => {
583
- i.access?.viaEntity === void 0 && i.access?.scope === void 0 && e.logger.warn("comments: no access rule declared — EVERY read and write will be refused (fail-closed). Set commentsPlugin({ access: { viaEntity } }) or { access: { scope } }."), e.logger.info("comments active", { mentions: i.resolveMentions !== void 0 });
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: () => v.sync(() => {
586
- o = void 0, s = void 0;
585
+ onDeactivate: () => y.sync(() => {
586
+ _ = void 0, v = void 0;
587
587
  })
588
588
  });
589
- }, G = async (e, t, n = /* @__PURE__ */ new Date()) => {
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", b(S("status", "resolved"), S("kind", o)))) {
602
- let o = [...await r("_voltro_comment_thread_events", S("threadId", String(c.id)))], l = (e) => new Date(e.at instanceof Date ? e.at : String(e.at)).getTime();
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", S("threadId", String(c.id)));
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", S("commentId", String(t.id)))) await e.delete("_voltro_comment_reactions", String(n.id));
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", S("threadId", String(c.id)))) await e.delete("_voltro_comment_reads", String(t.id));
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: C({
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
- }, K = () => "plugin-comments";
634
- export { c as COMMENT_THREAD_KINDS, e as CommentAccessRefused, t as CommentNotFound, n as CommentNotYours, r as CommentStatusRefused, i as QUOTE_MAX_LENGTH, G as applyCommentRetention, B as commentReactionsTable, V as commentReadsTable, z as commentThreadEventsTable, L as commentThreadsTable, l as commentsFeed, W as commentsPlugin, R as commentsTable, a as findQuote, K as pluginComments, o as textQuote };
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 };