@vllnt/convex-comments 0.1.0-canary.3e5064a
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/LICENSE +21 -0
- package/README.md +130 -0
- package/dist/client/index.d.ts +146 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +133 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/types.d.ts +51 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +3 -0
- package/dist/client/types.js.map +1 -0
- package/dist/component/_generated/api.d.ts +40 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +98 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +121 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +78 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/convex.config.d.ts +3 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +7 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/crons.d.ts +16 -0
- package/dist/component/crons.d.ts.map +1 -0
- package/dist/component/crons.js +19 -0
- package/dist/component/crons.js.map +1 -0
- package/dist/component/mutations.d.ts +81 -0
- package/dist/component/mutations.d.ts.map +1 -0
- package/dist/component/mutations.js +223 -0
- package/dist/component/mutations.js.map +1 -0
- package/dist/component/queries.d.ts +61 -0
- package/dist/component/queries.d.ts.map +1 -0
- package/dist/component/queries.js +82 -0
- package/dist/component/queries.js.map +1 -0
- package/dist/component/schema.d.ts +42 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +34 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/component/validators.d.ts +46 -0
- package/dist/component/validators.d.ts.map +1 -0
- package/dist/component/validators.js +37 -0
- package/dist/component/validators.js.map +1 -0
- package/dist/shared.d.ts +25 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +26 -0
- package/dist/shared.js.map +1 -0
- package/package.json +98 -0
- package/src/client/index.ts +299 -0
- package/src/client/types.ts +55 -0
- package/src/component/_generated/api.ts +56 -0
- package/src/component/_generated/component.ts +129 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +156 -0
- package/src/component/convex.config.ts +9 -0
- package/src/component/crons.ts +23 -0
- package/src/component/mutations.ts +234 -0
- package/src/component/queries.ts +96 -0
- package/src/component/schema.ts +34 -0
- package/src/component/validators.ts +44 -0
- package/src/shared.ts +33 -0
- package/src/test.ts +15 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { ConvexError, v } from "convex/values";
|
|
2
|
+
import { api } from "./_generated/api";
|
|
3
|
+
import { mutation } from "./_generated/server";
|
|
4
|
+
import { jsonValue } from "./validators";
|
|
5
|
+
/**
|
|
6
|
+
* Post a comment on a resource and return its id. The comment is inserted `open`
|
|
7
|
+
* with `createdAt`/`updatedAt` stamped from the server clock (`Date.now()` inside
|
|
8
|
+
* the handler — never caller-supplied). `resourceRef` (the thing commented on) and
|
|
9
|
+
* `authorRef` (who wrote it) are opaque host refs the component never inspects;
|
|
10
|
+
* `body` is opaque host data narrowed by the host's `bodyValidator` at the client
|
|
11
|
+
* boundary. `parentId`, when given, threads this comment as a reply to an existing
|
|
12
|
+
* comment.
|
|
13
|
+
*
|
|
14
|
+
* @throws `ConvexError({ code: "PARENT_NOT_FOUND" })` when `parentId` names no
|
|
15
|
+
* comment.
|
|
16
|
+
* @throws `ConvexError({ code: "PARENT_MISMATCH" })` when the parent belongs to a
|
|
17
|
+
* different resource — a reply must live on the same resource as its parent.
|
|
18
|
+
* @throws `ConvexError({ code: "PARENT_DELETED" })` when the parent is soft-deleted
|
|
19
|
+
* — you cannot reply under a removed comment.
|
|
20
|
+
*/
|
|
21
|
+
export const post = mutation({
|
|
22
|
+
args: {
|
|
23
|
+
resourceRef: v.string(),
|
|
24
|
+
authorRef: v.string(),
|
|
25
|
+
body: jsonValue,
|
|
26
|
+
parentId: v.optional(v.id("comments")),
|
|
27
|
+
},
|
|
28
|
+
returns: v.object({ commentId: v.id("comments") }),
|
|
29
|
+
handler: async (ctx, args) => {
|
|
30
|
+
if (args.parentId !== undefined) {
|
|
31
|
+
const parent = await ctx.db.get(args.parentId);
|
|
32
|
+
if (parent === null) {
|
|
33
|
+
throw new ConvexError({
|
|
34
|
+
code: "PARENT_NOT_FOUND",
|
|
35
|
+
message: `parent comment "${args.parentId}" not found`,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (parent.resourceRef !== args.resourceRef) {
|
|
39
|
+
throw new ConvexError({
|
|
40
|
+
code: "PARENT_MISMATCH",
|
|
41
|
+
message: `parent comment belongs to a different resource`,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (parent.status === "deleted") {
|
|
45
|
+
throw new ConvexError({
|
|
46
|
+
code: "PARENT_DELETED",
|
|
47
|
+
message: `cannot reply under a deleted comment`,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const now = Date.now();
|
|
52
|
+
const commentId = await ctx.db.insert("comments", {
|
|
53
|
+
resourceRef: args.resourceRef,
|
|
54
|
+
authorRef: args.authorRef,
|
|
55
|
+
parentId: args.parentId,
|
|
56
|
+
body: args.body,
|
|
57
|
+
status: "open",
|
|
58
|
+
createdAt: now,
|
|
59
|
+
updatedAt: now,
|
|
60
|
+
});
|
|
61
|
+
return { commentId };
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
/**
|
|
65
|
+
* Edit a comment's body. Only the original author may edit — a non-author caller
|
|
66
|
+
* is rejected (`NOT_AUTHOR`). A soft-deleted comment cannot be edited
|
|
67
|
+
* (`DELETED`). Records `editedAt` (and `updatedAt`) from the server clock; the
|
|
68
|
+
* new `body` is opaque host data narrowed at the client boundary.
|
|
69
|
+
*
|
|
70
|
+
* @throws `ConvexError({ code: "NOT_FOUND" })` when no comment has `commentId`.
|
|
71
|
+
* @throws `ConvexError({ code: "NOT_AUTHOR" })` when `authorRef` is not the author.
|
|
72
|
+
* @throws `ConvexError({ code: "DELETED" })` when the comment is soft-deleted.
|
|
73
|
+
*/
|
|
74
|
+
export const edit = mutation({
|
|
75
|
+
args: {
|
|
76
|
+
commentId: v.id("comments"),
|
|
77
|
+
authorRef: v.string(),
|
|
78
|
+
body: jsonValue,
|
|
79
|
+
},
|
|
80
|
+
returns: v.null(),
|
|
81
|
+
handler: async (ctx, args) => {
|
|
82
|
+
const comment = await ctx.db.get(args.commentId);
|
|
83
|
+
if (comment === null) {
|
|
84
|
+
throw new ConvexError({
|
|
85
|
+
code: "NOT_FOUND",
|
|
86
|
+
message: `comment "${args.commentId}" not found`,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (comment.authorRef !== args.authorRef) {
|
|
90
|
+
throw new ConvexError({
|
|
91
|
+
code: "NOT_AUTHOR",
|
|
92
|
+
message: `only the author may edit this comment`,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (comment.status === "deleted") {
|
|
96
|
+
throw new ConvexError({
|
|
97
|
+
code: "DELETED",
|
|
98
|
+
message: `comment "${args.commentId}" is deleted and cannot be edited`,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
const now = Date.now();
|
|
102
|
+
await ctx.db.patch(comment._id, {
|
|
103
|
+
body: args.body,
|
|
104
|
+
editedAt: now,
|
|
105
|
+
updatedAt: now,
|
|
106
|
+
});
|
|
107
|
+
return null;
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
/**
|
|
111
|
+
* Soft-delete a comment. Only the original author may delete it (`NOT_AUTHOR`).
|
|
112
|
+
* The row is kept (its replies are preserved) but moved to `deleted` status with
|
|
113
|
+
* its `body` cleared, so the prune cron can sweep it after the retention window.
|
|
114
|
+
* Idempotent — re-deleting an already-deleted comment is a no-op.
|
|
115
|
+
*
|
|
116
|
+
* @throws `ConvexError({ code: "NOT_FOUND" })` when no comment has `commentId`.
|
|
117
|
+
* @throws `ConvexError({ code: "NOT_AUTHOR" })` when `authorRef` is not the author.
|
|
118
|
+
*/
|
|
119
|
+
export const remove = mutation({
|
|
120
|
+
args: { commentId: v.id("comments"), authorRef: v.string() },
|
|
121
|
+
returns: v.null(),
|
|
122
|
+
handler: async (ctx, args) => {
|
|
123
|
+
const comment = await ctx.db.get(args.commentId);
|
|
124
|
+
if (comment === null) {
|
|
125
|
+
throw new ConvexError({
|
|
126
|
+
code: "NOT_FOUND",
|
|
127
|
+
message: `comment "${args.commentId}" not found`,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
if (comment.authorRef !== args.authorRef) {
|
|
131
|
+
throw new ConvexError({
|
|
132
|
+
code: "NOT_AUTHOR",
|
|
133
|
+
message: `only the author may delete this comment`,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
if (comment.status === "deleted") {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
await ctx.db.patch(comment._id, {
|
|
140
|
+
status: "deleted",
|
|
141
|
+
body: undefined,
|
|
142
|
+
updatedAt: Date.now(),
|
|
143
|
+
});
|
|
144
|
+
return null;
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
/**
|
|
148
|
+
* Toggle a comment's resolved state. Only the original author may resolve/reopen
|
|
149
|
+
* (`NOT_AUTHOR`); a soft-deleted comment cannot be resolved (`DELETED`). Setting
|
|
150
|
+
* `resolved: true` moves an `open` comment to `resolved`; `false` reopens it. The
|
|
151
|
+
* target is idempotent — setting the state it already holds is a no-op.
|
|
152
|
+
*
|
|
153
|
+
* @throws `ConvexError({ code: "NOT_FOUND" })` when no comment has `commentId`.
|
|
154
|
+
* @throws `ConvexError({ code: "NOT_AUTHOR" })` when `authorRef` is not the author.
|
|
155
|
+
* @throws `ConvexError({ code: "DELETED" })` when the comment is soft-deleted.
|
|
156
|
+
*/
|
|
157
|
+
export const resolve = mutation({
|
|
158
|
+
args: {
|
|
159
|
+
commentId: v.id("comments"),
|
|
160
|
+
authorRef: v.string(),
|
|
161
|
+
resolved: v.boolean(),
|
|
162
|
+
},
|
|
163
|
+
returns: v.null(),
|
|
164
|
+
handler: async (ctx, args) => {
|
|
165
|
+
const comment = await ctx.db.get(args.commentId);
|
|
166
|
+
if (comment === null) {
|
|
167
|
+
throw new ConvexError({
|
|
168
|
+
code: "NOT_FOUND",
|
|
169
|
+
message: `comment "${args.commentId}" not found`,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
if (comment.authorRef !== args.authorRef) {
|
|
173
|
+
throw new ConvexError({
|
|
174
|
+
code: "NOT_AUTHOR",
|
|
175
|
+
message: `only the author may resolve this comment`,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
if (comment.status === "deleted") {
|
|
179
|
+
throw new ConvexError({
|
|
180
|
+
code: "DELETED",
|
|
181
|
+
message: `comment "${args.commentId}" is deleted and cannot be resolved`,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
const target = args.resolved ? "resolved" : "open";
|
|
185
|
+
if (comment.status === target) {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
await ctx.db.patch(comment._id, { status: target, updatedAt: Date.now() });
|
|
189
|
+
return null;
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
/**
|
|
193
|
+
* Delete up to `batch` soft-deleted comments whose `updatedAt < before`, oldest
|
|
194
|
+
* first, via the `by_status_updated` index. `before` defaults to the server clock
|
|
195
|
+
* (`Date.now()`) when omitted, so the built-in cron sweeps exactly the comments
|
|
196
|
+
* deleted-and-stale as of the run. If a full batch was removed there may be more,
|
|
197
|
+
* so the sweep self-reschedules through `ctx.scheduler` until a short batch
|
|
198
|
+
* signals the tail is clean. Idempotent: only ever removes already-`deleted`,
|
|
199
|
+
* past-retention rows. Open and resolved comments are never pruned.
|
|
200
|
+
*/
|
|
201
|
+
export const prune = mutation({
|
|
202
|
+
args: { before: v.optional(v.number()), batch: v.number() },
|
|
203
|
+
returns: v.number(),
|
|
204
|
+
handler: async (ctx, args) => {
|
|
205
|
+
const before = args.before ?? Date.now();
|
|
206
|
+
const stale = await ctx.db
|
|
207
|
+
.query("comments")
|
|
208
|
+
.withIndex("by_status_updated", (q) => q.eq("status", "deleted").lt("updatedAt", before))
|
|
209
|
+
.take(args.batch);
|
|
210
|
+
for (const row of stale) {
|
|
211
|
+
await ctx.db.delete(row._id);
|
|
212
|
+
}
|
|
213
|
+
const removed = stale.length;
|
|
214
|
+
if (removed === args.batch) {
|
|
215
|
+
await ctx.scheduler.runAfter(0, api.mutations.prune, {
|
|
216
|
+
before,
|
|
217
|
+
batch: args.batch,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
return removed;
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
//# sourceMappingURL=mutations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutations.js","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,QAAQ,CAAC;IAC3B,IAAI,EAAE;QACJ,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;QACvB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE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AC;QACL,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/** The current view of one comment, or `null` if no such id is held. */
|
|
2
|
+
export declare const get: import("convex/server").RegisteredQuery<"public", {
|
|
3
|
+
commentId: import("convex/values").GenericId<"comments">;
|
|
4
|
+
}, Promise<{
|
|
5
|
+
commentId: import("convex/values").GenericId<"comments">;
|
|
6
|
+
resourceRef: string;
|
|
7
|
+
authorRef: string;
|
|
8
|
+
parentId: import("convex/values").GenericId<"comments"> | undefined;
|
|
9
|
+
body: any;
|
|
10
|
+
status: "open" | "resolved" | "deleted";
|
|
11
|
+
editedAt: number | undefined;
|
|
12
|
+
createdAt: number;
|
|
13
|
+
updatedAt: number;
|
|
14
|
+
} | null>>;
|
|
15
|
+
/**
|
|
16
|
+
* Page comments on one `resourceRef`, oldest first. By default only top-level
|
|
17
|
+
* comments are returned (`parentId === undefined`); pass `parentId` to page one
|
|
18
|
+
* comment's direct replies via the `by_resource_parent` index. Soft-deleted
|
|
19
|
+
* comments are excluded unless `includeDeleted` is set. Returns the standard
|
|
20
|
+
* Convex paginated envelope (`page`, `isDone`, `continueCursor`) so the host can
|
|
21
|
+
* render a thread reactively.
|
|
22
|
+
*/
|
|
23
|
+
export declare const list: import("convex/server").RegisteredQuery<"public", {
|
|
24
|
+
parentId?: import("convex/values").GenericId<"comments"> | undefined;
|
|
25
|
+
includeDeleted?: boolean | undefined;
|
|
26
|
+
resourceRef: string;
|
|
27
|
+
paginationOpts: {
|
|
28
|
+
id?: number;
|
|
29
|
+
endCursor?: string | null;
|
|
30
|
+
maximumRowsRead?: number;
|
|
31
|
+
maximumBytesRead?: number;
|
|
32
|
+
numItems: number;
|
|
33
|
+
cursor: string | null;
|
|
34
|
+
};
|
|
35
|
+
}, Promise<{
|
|
36
|
+
page: {
|
|
37
|
+
commentId: import("convex/values").GenericId<"comments">;
|
|
38
|
+
resourceRef: string;
|
|
39
|
+
authorRef: string;
|
|
40
|
+
parentId: import("convex/values").GenericId<"comments"> | undefined;
|
|
41
|
+
body: any;
|
|
42
|
+
status: "open" | "resolved" | "deleted";
|
|
43
|
+
editedAt: number | undefined;
|
|
44
|
+
createdAt: number;
|
|
45
|
+
updatedAt: number;
|
|
46
|
+
}[];
|
|
47
|
+
isDone: boolean;
|
|
48
|
+
continueCursor: import("convex/server").Cursor;
|
|
49
|
+
splitCursor?: import("convex/server").Cursor | null;
|
|
50
|
+
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
51
|
+
}>>;
|
|
52
|
+
/**
|
|
53
|
+
* Count the visible (non-deleted) comments on one `resourceRef`. Reads the whole
|
|
54
|
+
* resource slice via the `by_resource` index and tallies the open/resolved rows —
|
|
55
|
+
* a small per-resource scan, not a global one. Soft-deleted comments are never
|
|
56
|
+
* counted.
|
|
57
|
+
*/
|
|
58
|
+
export declare const count: import("convex/server").RegisteredQuery<"public", {
|
|
59
|
+
resourceRef: string;
|
|
60
|
+
}, Promise<number>>;
|
|
61
|
+
//# sourceMappingURL=queries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../src/component/queries.ts"],"names":[],"mappings":"AAsBA,wEAAwE;AACxE,eAAO,MAAM,GAAG;;;;;;;;;;;;UAOd,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCf,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,KAAK;;mBAUhB,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { paginationOptsValidator } from "convex/server";
|
|
3
|
+
import { query } from "./_generated/server";
|
|
4
|
+
import { commentView } from "./validators";
|
|
5
|
+
import { VISIBLE_STATUSES } from "../shared";
|
|
6
|
+
/** Project a stored comment row to its public view (exposes the id as a string). */
|
|
7
|
+
function view(comment) {
|
|
8
|
+
return {
|
|
9
|
+
commentId: comment._id,
|
|
10
|
+
resourceRef: comment.resourceRef,
|
|
11
|
+
authorRef: comment.authorRef,
|
|
12
|
+
parentId: comment.parentId,
|
|
13
|
+
body: comment.body,
|
|
14
|
+
status: comment.status,
|
|
15
|
+
editedAt: comment.editedAt,
|
|
16
|
+
createdAt: comment.createdAt,
|
|
17
|
+
updatedAt: comment.updatedAt,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** The current view of one comment, or `null` if no such id is held. */
|
|
21
|
+
export const get = query({
|
|
22
|
+
args: { commentId: v.id("comments") },
|
|
23
|
+
returns: v.union(v.null(), commentView),
|
|
24
|
+
handler: async (ctx, args) => {
|
|
25
|
+
const comment = await ctx.db.get(args.commentId);
|
|
26
|
+
return comment === null ? null : view(comment);
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Page comments on one `resourceRef`, oldest first. By default only top-level
|
|
31
|
+
* comments are returned (`parentId === undefined`); pass `parentId` to page one
|
|
32
|
+
* comment's direct replies via the `by_resource_parent` index. Soft-deleted
|
|
33
|
+
* comments are excluded unless `includeDeleted` is set. Returns the standard
|
|
34
|
+
* Convex paginated envelope (`page`, `isDone`, `continueCursor`) so the host can
|
|
35
|
+
* render a thread reactively.
|
|
36
|
+
*/
|
|
37
|
+
export const list = query({
|
|
38
|
+
args: {
|
|
39
|
+
resourceRef: v.string(),
|
|
40
|
+
parentId: v.optional(v.id("comments")),
|
|
41
|
+
includeDeleted: v.optional(v.boolean()),
|
|
42
|
+
paginationOpts: paginationOptsValidator,
|
|
43
|
+
},
|
|
44
|
+
returns: v.object({
|
|
45
|
+
page: v.array(commentView),
|
|
46
|
+
isDone: v.boolean(),
|
|
47
|
+
continueCursor: v.string(),
|
|
48
|
+
splitCursor: v.optional(v.union(v.string(), v.null())),
|
|
49
|
+
pageStatus: v.optional(v.union(v.literal("SplitRecommended"), v.literal("SplitRequired"), v.null())),
|
|
50
|
+
}),
|
|
51
|
+
handler: async (ctx, args) => {
|
|
52
|
+
// `by_resource_parent` keys on (resourceRef, parentId): an omitted `parentId`
|
|
53
|
+
// pages the resource's top level (root comments, `parentId === undefined`); a
|
|
54
|
+
// given `parentId` pages that comment's direct replies.
|
|
55
|
+
const base = ctx.db
|
|
56
|
+
.query("comments")
|
|
57
|
+
.withIndex("by_resource_parent", (q) => q.eq("resourceRef", args.resourceRef).eq("parentId", args.parentId));
|
|
58
|
+
const filtered = args.includeDeleted
|
|
59
|
+
? base
|
|
60
|
+
: base.filter((q) => q.neq(q.field("status"), "deleted"));
|
|
61
|
+
const result = await filtered.order("asc").paginate(args.paginationOpts);
|
|
62
|
+
return { ...result, page: result.page.map(view) };
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* Count the visible (non-deleted) comments on one `resourceRef`. Reads the whole
|
|
67
|
+
* resource slice via the `by_resource` index and tallies the open/resolved rows —
|
|
68
|
+
* a small per-resource scan, not a global one. Soft-deleted comments are never
|
|
69
|
+
* counted.
|
|
70
|
+
*/
|
|
71
|
+
export const count = query({
|
|
72
|
+
args: { resourceRef: v.string() },
|
|
73
|
+
returns: v.number(),
|
|
74
|
+
handler: async (ctx, args) => {
|
|
75
|
+
const all = await ctx.db
|
|
76
|
+
.query("comments")
|
|
77
|
+
.withIndex("by_resource", (q) => q.eq("resourceRef", args.resourceRef))
|
|
78
|
+
.collect();
|
|
79
|
+
return all.filter((c) => VISIBLE_STATUSES.has(c.status)).length;
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
//# sourceMappingURL=queries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../src/component/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,KAAK,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E,SAAS,CAAC,CAAC,CAAC;QAE5D,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QACzE,OAAO,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;IACpD,CAAC;CACF,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,CAAC;IACzB,IAAI,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE;IACjC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC3B,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,EAAE;aACrB,KAAK,CAAC,UAAU,CAAC;aACjB,SAAS,CAAC,aAAa,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;aACtE,OAAO,EAAE,CAAC;QACb,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IAClE,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandboxed table — the comment tree's own concern. A comment is attached to an
|
|
3
|
+
* opaque host `resourceRef` (the thing being commented on) and authored by an
|
|
4
|
+
* opaque `authorRef`; the host owns the meaning of both. `parentId` is the opaque
|
|
5
|
+
* id of the comment this one replies to (absent at the top level), so the tree is
|
|
6
|
+
* a self-referential thread. `body` is opaque host data (cleared on soft-delete);
|
|
7
|
+
* `status` tracks the lifecycle. `editedAt` records the last edit, distinct from
|
|
8
|
+
* `updatedAt` (any write).
|
|
9
|
+
*
|
|
10
|
+
* The three indexes serve: list/count one resource oldest-first (`by_resource`),
|
|
11
|
+
* walk one parent's direct replies (`by_resource_parent`), list one author's
|
|
12
|
+
* comments (`by_author`), and the retention sweep of soft-deleted rows
|
|
13
|
+
* (`by_status_updated`).
|
|
14
|
+
*/
|
|
15
|
+
declare const _default: import("convex/server").SchemaDefinition<{
|
|
16
|
+
comments: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
17
|
+
body?: any;
|
|
18
|
+
parentId?: import("convex/values").GenericId<"comments"> | undefined;
|
|
19
|
+
editedAt?: number | undefined;
|
|
20
|
+
resourceRef: string;
|
|
21
|
+
authorRef: string;
|
|
22
|
+
status: "open" | "resolved" | "deleted";
|
|
23
|
+
createdAt: number;
|
|
24
|
+
updatedAt: number;
|
|
25
|
+
}, {
|
|
26
|
+
resourceRef: import("convex/values").VString<string, "required">;
|
|
27
|
+
authorRef: import("convex/values").VString<string, "required">;
|
|
28
|
+
parentId: import("convex/values").VId<import("convex/values").GenericId<"comments"> | undefined, "optional">;
|
|
29
|
+
body: import("convex/values").VAny<any, "optional", string>;
|
|
30
|
+
status: import("convex/values").VUnion<"open" | "resolved" | "deleted", [import("convex/values").VLiteral<"open", "required">, import("convex/values").VLiteral<"resolved", "required">, import("convex/values").VLiteral<"deleted", "required">], "required", never>;
|
|
31
|
+
editedAt: import("convex/values").VFloat64<number | undefined, "optional">;
|
|
32
|
+
createdAt: import("convex/values").VFloat64<number, "required">;
|
|
33
|
+
updatedAt: import("convex/values").VFloat64<number, "required">;
|
|
34
|
+
}, "required", "resourceRef" | "authorRef" | "body" | "parentId" | "status" | "editedAt" | "createdAt" | "updatedAt" | `body.${string}`>, {
|
|
35
|
+
by_resource: ["resourceRef", "createdAt", "_creationTime"];
|
|
36
|
+
by_resource_parent: ["resourceRef", "parentId", "createdAt", "_creationTime"];
|
|
37
|
+
by_author: ["authorRef", "createdAt", "_creationTime"];
|
|
38
|
+
by_status_updated: ["status", "updatedAt", "_creationTime"];
|
|
39
|
+
}, {}, {}>;
|
|
40
|
+
}, true>;
|
|
41
|
+
export default _default;
|
|
42
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/component/schema.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;GAaG;;;;;;;;;;;;;;;;;;;;;;;;;;;AACH,wBAeG"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { defineSchema, defineTable } from "convex/server";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
import { commentStatus, jsonValue } from "./validators";
|
|
4
|
+
/**
|
|
5
|
+
* Sandboxed table — the comment tree's own concern. A comment is attached to an
|
|
6
|
+
* opaque host `resourceRef` (the thing being commented on) and authored by an
|
|
7
|
+
* opaque `authorRef`; the host owns the meaning of both. `parentId` is the opaque
|
|
8
|
+
* id of the comment this one replies to (absent at the top level), so the tree is
|
|
9
|
+
* a self-referential thread. `body` is opaque host data (cleared on soft-delete);
|
|
10
|
+
* `status` tracks the lifecycle. `editedAt` records the last edit, distinct from
|
|
11
|
+
* `updatedAt` (any write).
|
|
12
|
+
*
|
|
13
|
+
* The three indexes serve: list/count one resource oldest-first (`by_resource`),
|
|
14
|
+
* walk one parent's direct replies (`by_resource_parent`), list one author's
|
|
15
|
+
* comments (`by_author`), and the retention sweep of soft-deleted rows
|
|
16
|
+
* (`by_status_updated`).
|
|
17
|
+
*/
|
|
18
|
+
export default defineSchema({
|
|
19
|
+
comments: defineTable({
|
|
20
|
+
resourceRef: v.string(),
|
|
21
|
+
authorRef: v.string(),
|
|
22
|
+
parentId: v.optional(v.id("comments")),
|
|
23
|
+
body: v.optional(jsonValue),
|
|
24
|
+
status: commentStatus,
|
|
25
|
+
editedAt: v.optional(v.number()),
|
|
26
|
+
createdAt: v.number(),
|
|
27
|
+
updatedAt: v.number(),
|
|
28
|
+
})
|
|
29
|
+
.index("by_resource", ["resourceRef", "createdAt"])
|
|
30
|
+
.index("by_resource_parent", ["resourceRef", "parentId", "createdAt"])
|
|
31
|
+
.index("by_author", ["authorRef", "createdAt"])
|
|
32
|
+
.index("by_status_updated", ["status", "updatedAt"]),
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/component/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAExD;;;;;;;;;;;;;GAaG;AACH,eAAe,YAAY,CAAC;IAC1B,QAAQ,EAAE,WAAW,CAAC;QACpB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;QACvB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;QACrB,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC;QACtC,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC;QAC3B,MAAM,EAAE,aAAa;QACrB,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QAChC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;QACrB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;KACtB,CAAC;SACC,KAAK,CAAC,aAAa,EAAE,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;SAClD,KAAK,CAAC,oBAAoB,EAAE,CAAC,aAAa,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;SACrE,KAAK,CAAC,WAAW,EAAE,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;SAC9C,KAAK,CAAC,mBAAmB,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;CACvD,CAAC,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opaque host-owned comment body — plain text, a rich-block JSON document, or
|
|
3
|
+
* whatever shape the host's editor produces. The component never inspects it; it
|
|
4
|
+
* is last-resort arbitrary data, aliased here rather than left bare in a function
|
|
5
|
+
* signature. The host narrows it at the {@link Comments} client boundary via an
|
|
6
|
+
* optional `bodyValidator` parser.
|
|
7
|
+
*
|
|
8
|
+
* This is the single documented `v.any()` escape hatch in the component; the lint
|
|
9
|
+
* rule `convex-rules/no-bare-v-any` is satisfied by routing every arbitrary host
|
|
10
|
+
* body through this alias instead of a bare `v.any()`.
|
|
11
|
+
*/
|
|
12
|
+
export declare const jsonValue: import("convex/values").VAny<any, "required", string>;
|
|
13
|
+
/** The three lifecycle statuses a comment moves through. */
|
|
14
|
+
export declare const commentStatus: import("convex/values").VUnion<"open" | "resolved" | "deleted", [import("convex/values").VLiteral<"open", "required">, import("convex/values").VLiteral<"resolved", "required">, import("convex/values").VLiteral<"deleted", "required">], "required", never>;
|
|
15
|
+
/**
|
|
16
|
+
* The visible (non-deleted) status subset a `list` filters on. A soft-deleted
|
|
17
|
+
* comment is excluded from a normal listing.
|
|
18
|
+
*/
|
|
19
|
+
export declare const visibleStatus: import("convex/values").VUnion<"open" | "resolved", [import("convex/values").VLiteral<"open", "required">, import("convex/values").VLiteral<"resolved", "required">], "required", never>;
|
|
20
|
+
/**
|
|
21
|
+
* Public projection of a comment returned by {@link get} / {@link list}. `body`
|
|
22
|
+
* is opaque host data (`undefined` once soft-deleted — the body is cleared);
|
|
23
|
+
* `parentId` is the opaque id of the comment this one replies to, when threaded.
|
|
24
|
+
*/
|
|
25
|
+
export declare const commentView: import("convex/values").VObject<{
|
|
26
|
+
body?: any;
|
|
27
|
+
parentId?: string | undefined;
|
|
28
|
+
editedAt?: number | undefined;
|
|
29
|
+
resourceRef: string;
|
|
30
|
+
authorRef: string;
|
|
31
|
+
commentId: string;
|
|
32
|
+
status: "open" | "resolved" | "deleted";
|
|
33
|
+
createdAt: number;
|
|
34
|
+
updatedAt: number;
|
|
35
|
+
}, {
|
|
36
|
+
commentId: import("convex/values").VString<string, "required">;
|
|
37
|
+
resourceRef: import("convex/values").VString<string, "required">;
|
|
38
|
+
authorRef: import("convex/values").VString<string, "required">;
|
|
39
|
+
parentId: import("convex/values").VString<string | undefined, "optional">;
|
|
40
|
+
body: import("convex/values").VAny<any, "optional", string>;
|
|
41
|
+
status: import("convex/values").VUnion<"open" | "resolved" | "deleted", [import("convex/values").VLiteral<"open", "required">, import("convex/values").VLiteral<"resolved", "required">, import("convex/values").VLiteral<"deleted", "required">], "required", never>;
|
|
42
|
+
editedAt: import("convex/values").VFloat64<number | undefined, "optional">;
|
|
43
|
+
createdAt: import("convex/values").VFloat64<number, "required">;
|
|
44
|
+
updatedAt: import("convex/values").VFloat64<number, "required">;
|
|
45
|
+
}, "required", "resourceRef" | "authorRef" | "body" | "parentId" | "commentId" | "status" | "editedAt" | "createdAt" | "updatedAt" | `body.${string}`>;
|
|
46
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,uDAAU,CAAC;AAEjC,4DAA4D;AAC5D,eAAO,MAAM,aAAa,+PAIzB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,0LAAoD,CAAC;AAE/E;;;;GAIG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;sJAUtB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
/**
|
|
3
|
+
* Opaque host-owned comment body — plain text, a rich-block JSON document, or
|
|
4
|
+
* whatever shape the host's editor produces. The component never inspects it; it
|
|
5
|
+
* is last-resort arbitrary data, aliased here rather than left bare in a function
|
|
6
|
+
* signature. The host narrows it at the {@link Comments} client boundary via an
|
|
7
|
+
* optional `bodyValidator` parser.
|
|
8
|
+
*
|
|
9
|
+
* This is the single documented `v.any()` escape hatch in the component; the lint
|
|
10
|
+
* rule `convex-rules/no-bare-v-any` is satisfied by routing every arbitrary host
|
|
11
|
+
* body through this alias instead of a bare `v.any()`.
|
|
12
|
+
*/
|
|
13
|
+
export const jsonValue = v.any();
|
|
14
|
+
/** The three lifecycle statuses a comment moves through. */
|
|
15
|
+
export const commentStatus = v.union(v.literal("open"), v.literal("resolved"), v.literal("deleted"));
|
|
16
|
+
/**
|
|
17
|
+
* The visible (non-deleted) status subset a `list` filters on. A soft-deleted
|
|
18
|
+
* comment is excluded from a normal listing.
|
|
19
|
+
*/
|
|
20
|
+
export const visibleStatus = v.union(v.literal("open"), v.literal("resolved"));
|
|
21
|
+
/**
|
|
22
|
+
* Public projection of a comment returned by {@link get} / {@link list}. `body`
|
|
23
|
+
* is opaque host data (`undefined` once soft-deleted — the body is cleared);
|
|
24
|
+
* `parentId` is the opaque id of the comment this one replies to, when threaded.
|
|
25
|
+
*/
|
|
26
|
+
export const commentView = v.object({
|
|
27
|
+
commentId: v.string(),
|
|
28
|
+
resourceRef: v.string(),
|
|
29
|
+
authorRef: v.string(),
|
|
30
|
+
parentId: v.optional(v.string()),
|
|
31
|
+
body: v.optional(jsonValue),
|
|
32
|
+
status: commentStatus,
|
|
33
|
+
editedAt: v.optional(v.number()),
|
|
34
|
+
createdAt: v.number(),
|
|
35
|
+
updatedAt: v.number(),
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAElC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;AAEjC,4DAA4D;AAC5D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAClC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EACjB,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,EACrB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CACrB,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;AAE/E;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;IACvB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAChC,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC;IAC3B,MAAM,EAAE,aAAa;IACrB,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAChC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CACtB,CAAC,CAAC"}
|
package/dist/shared.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Shared constants used by both `client/` and `component/`. */
|
|
2
|
+
export declare const COMPONENT_NAME = "comments";
|
|
3
|
+
/**
|
|
4
|
+
* The lifecycle statuses a comment moves through. `open` is the freshly-posted
|
|
5
|
+
* state; `resolve` toggles it to `resolved` and back; a soft `delete` moves it to
|
|
6
|
+
* the terminal `deleted` state (the row is kept for retention, its `body` cleared).
|
|
7
|
+
*/
|
|
8
|
+
export declare const COMMENT_STATUSES: readonly ["open", "resolved", "deleted"];
|
|
9
|
+
/** A single comment lifecycle status. */
|
|
10
|
+
export type CommentStatus = (typeof COMMENT_STATUSES)[number];
|
|
11
|
+
/**
|
|
12
|
+
* The non-deleted statuses a `list` returns by default — a soft-deleted comment
|
|
13
|
+
* is excluded from a normal listing (the host opts in with `includeDeleted`).
|
|
14
|
+
*/
|
|
15
|
+
export declare const VISIBLE_STATUSES: ReadonlySet<CommentStatus>;
|
|
16
|
+
/**
|
|
17
|
+
* Default retention (ms) for soft-deleted comments before the prune cron sweeps
|
|
18
|
+
* them: 30 days. Bounds unbounded growth of the `comments` table while leaving a
|
|
19
|
+
* window in which a deletion can still be audited. A host that wants a different
|
|
20
|
+
* window drives `prune` from its own scheduler with an explicit `before` cutoff.
|
|
21
|
+
*/
|
|
22
|
+
export declare const DEFAULT_RETENTION_MS = 2592000000;
|
|
23
|
+
/** Default page size for a `prune` pass before the sweep self-reschedules. */
|
|
24
|
+
export declare const DEFAULT_PRUNE_BATCH = 200;
|
|
25
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAEhE,eAAO,MAAM,cAAc,aAAa,CAAC;AAEzC;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,0CAA2C,CAAC;AAEzE,yCAAyC;AACzC,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE9D;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,aAAa,CAGtD,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,aAAgB,CAAC;AAElD,8EAA8E;AAC9E,eAAO,MAAM,mBAAmB,MAAM,CAAC"}
|
package/dist/shared.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Shared constants used by both `client/` and `component/`. */
|
|
2
|
+
export const COMPONENT_NAME = "comments";
|
|
3
|
+
/**
|
|
4
|
+
* The lifecycle statuses a comment moves through. `open` is the freshly-posted
|
|
5
|
+
* state; `resolve` toggles it to `resolved` and back; a soft `delete` moves it to
|
|
6
|
+
* the terminal `deleted` state (the row is kept for retention, its `body` cleared).
|
|
7
|
+
*/
|
|
8
|
+
export const COMMENT_STATUSES = ["open", "resolved", "deleted"];
|
|
9
|
+
/**
|
|
10
|
+
* The non-deleted statuses a `list` returns by default — a soft-deleted comment
|
|
11
|
+
* is excluded from a normal listing (the host opts in with `includeDeleted`).
|
|
12
|
+
*/
|
|
13
|
+
export const VISIBLE_STATUSES = new Set([
|
|
14
|
+
"open",
|
|
15
|
+
"resolved",
|
|
16
|
+
]);
|
|
17
|
+
/**
|
|
18
|
+
* Default retention (ms) for soft-deleted comments before the prune cron sweeps
|
|
19
|
+
* them: 30 days. Bounds unbounded growth of the `comments` table while leaving a
|
|
20
|
+
* window in which a deletion can still be audited. A host that wants a different
|
|
21
|
+
* window drives `prune` from its own scheduler with an explicit `before` cutoff.
|
|
22
|
+
*/
|
|
23
|
+
export const DEFAULT_RETENTION_MS = 2_592_000_000;
|
|
24
|
+
/** Default page size for a `prune` pass before the sweep self-reschedules. */
|
|
25
|
+
export const DEFAULT_PRUNE_BATCH = 200;
|
|
26
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAEhE,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,CAAC;AAEzC;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,CAAU,CAAC;AAKzE;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAA+B,IAAI,GAAG,CAAC;IAClE,MAAM;IACN,UAAU;CACX,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAElD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAC"}
|