@cloudhal/comments 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +86 -2
- package/dist/src/client/comments.browser.js +245 -0
- package/dist/src/client/index.d.ts +19 -0
- package/dist/src/client/index.js +39 -0
- package/dist/src/client/solver.browser.js +118 -0
- package/dist/src/crypto.d.ts +64 -0
- package/dist/src/crypto.js +170 -0
- package/dist/src/errors.d.ts +38 -0
- package/dist/src/errors.js +61 -0
- package/dist/src/fixtures/comment-text.json +335 -0
- package/dist/src/hashes.d.ts +70 -0
- package/dist/src/hashes.js +191 -0
- package/dist/src/index.d.ts +24 -0
- package/dist/src/index.js +24 -0
- package/dist/src/limits.d.ts +73 -0
- package/dist/src/limits.js +227 -0
- package/dist/src/linkify.d.ts +53 -0
- package/dist/src/linkify.js +142 -0
- package/dist/src/model.d.ts +287 -0
- package/dist/src/model.js +341 -0
- package/dist/src/normalize.d.ts +17 -0
- package/dist/src/normalize.js +125 -0
- package/dist/src/pipeline.d.ts +176 -0
- package/dist/src/pipeline.js +898 -0
- package/dist/src/pow.d.ts +86 -0
- package/dist/src/pow.js +239 -0
- package/dist/src/purge.d.ts +87 -0
- package/dist/src/purge.js +186 -0
- package/dist/src/retention.d.ts +32 -0
- package/dist/src/retention.js +106 -0
- package/dist/src/rules.d.ts +68 -0
- package/dist/src/rules.js +218 -0
- package/dist/src/settings.d.ts +108 -0
- package/dist/src/settings.js +347 -0
- package/dist/src/sql/index.d.ts +7 -0
- package/dist/src/sql/index.js +29 -0
- package/dist/src/sql/portability.d.ts +113 -0
- package/dist/src/sql/portability.js +514 -0
- package/dist/src/sql/rows.d.ts +54 -0
- package/dist/src/sql/rows.js +145 -0
- package/dist/src/sql/store.d.ts +312 -0
- package/dist/src/sql/store.js +2111 -0
- package/dist/src/thread.d.ts +35 -0
- package/dist/src/thread.js +64 -0
- package/package.json +61 -3
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comment settings (RFC-0007 §4.5): per site in `comment_settings`, per collection inside the same
|
|
3
|
+
* row, per entry in `comment_threads`. Not a contract and not in the graph, so a content rollback
|
|
4
|
+
* never reopens comments and closing a thread takes effect at once. This module holds the types and
|
|
5
|
+
* the pure rules; `@cloudhal/comments/sql` reads and writes the rows (CAS on `rev`).
|
|
6
|
+
*/
|
|
7
|
+
import { CommentSettingsError } from "./errors.js";
|
|
8
|
+
import { LINK_HARD_LIMIT } from "./model.js";
|
|
9
|
+
import { foldForMatch } from "./rules.js";
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
/** Retention in days (§9.3). `null` = keep. */
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
export const DEFAULT_RETENTION = {
|
|
87
|
+
pendingDays: 30,
|
|
88
|
+
spamDays: 30,
|
|
89
|
+
deletedDays: 30,
|
|
90
|
+
hiddenDays: null,
|
|
91
|
+
clientDataDays: 30,
|
|
92
|
+
resolvedReportDays: 183,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The defaults: comments off (§0.2 D4), 90-day close, proof of work, JavaScript-less posts on
|
|
97
|
+
* (under proof of work only: off while Turnstile is on unless the owner allows them there too).
|
|
98
|
+
*/
|
|
99
|
+
export function defaultCommentSettings(siteId ) {
|
|
100
|
+
return {
|
|
101
|
+
siteId,
|
|
102
|
+
enabled: false,
|
|
103
|
+
showWhenOff: true,
|
|
104
|
+
collections: {},
|
|
105
|
+
closeAfterDays: 90,
|
|
106
|
+
protection: "pow",
|
|
107
|
+
turnstileSiteKey: null,
|
|
108
|
+
allowWithoutScript: true,
|
|
109
|
+
allowWithoutScriptWithTurnstile: false,
|
|
110
|
+
linkLimit: 2,
|
|
111
|
+
watchWords: [],
|
|
112
|
+
blockedWords: [],
|
|
113
|
+
dailyCap: 1000,
|
|
114
|
+
aiLabels: "off",
|
|
115
|
+
retention: DEFAULT_RETENTION,
|
|
116
|
+
planHint: null,
|
|
117
|
+
rev: 0,
|
|
118
|
+
updatedAt: null,
|
|
119
|
+
updatedBy: null,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Suggested `dailyCap` on Workers Paid (§6.5). */
|
|
124
|
+
export const PAID_DAILY_CAP = 5000;
|
|
125
|
+
export const MAX_DAILY_CAP = 100_000;
|
|
126
|
+
export const MAX_WORDS = 200;
|
|
127
|
+
export const MAX_WORD_LENGTH = 64;
|
|
128
|
+
export const MAX_COLLECTIONS = 100;
|
|
129
|
+
export const MAX_CLOSE_DAYS = 3650;
|
|
130
|
+
/**
|
|
131
|
+
* The longest IP hashes and challenge ids are kept (§9.1, §9.3). The disclosure snippet says "up
|
|
132
|
+
* to 30 days", so settings refuse more and the retention job clamps a stored value to it.
|
|
133
|
+
*/
|
|
134
|
+
export const MAX_CLIENT_DATA_DAYS = 30;
|
|
135
|
+
|
|
136
|
+
const SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
137
|
+
const SITE_KEY = /^[A-Za-z0-9_-]{1,128}$/;
|
|
138
|
+
|
|
139
|
+
const isInt = (v , min , max ) =>
|
|
140
|
+
typeof v === "number" && Number.isInteger(v) && v >= min && v <= max;
|
|
141
|
+
|
|
142
|
+
function checkDays(name , v , nullable , max = MAX_CLOSE_DAYS) {
|
|
143
|
+
if (v === null && nullable) return;
|
|
144
|
+
if (!isInt(v, 1, max))
|
|
145
|
+
throw new CommentSettingsError(
|
|
146
|
+
`${name} must be a whole number of days from 1 to ${max}${nullable ? " or null" : ""}`,
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** `clientDataDays` as the retention job applies it: never above `MAX_CLIENT_DATA_DAYS`. */
|
|
151
|
+
export function clientDataDays(retention ) {
|
|
152
|
+
const v = retention.clientDataDays;
|
|
153
|
+
return Number.isInteger(v) && v >= 1 ? Math.min(v, MAX_CLIENT_DATA_DAYS) : MAX_CLIENT_DATA_DAYS;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Word lists are stored trimmed, de-duplicated by their folded form, in the order given. */
|
|
157
|
+
export function normalizeWordList(name , words ) {
|
|
158
|
+
if (!Array.isArray(words)) throw new CommentSettingsError(`${name} must be a list of words`);
|
|
159
|
+
if (words.length > MAX_WORDS)
|
|
160
|
+
throw new CommentSettingsError(`${name} holds at most ${MAX_WORDS} entries`);
|
|
161
|
+
const seen = new Set ();
|
|
162
|
+
const out = [];
|
|
163
|
+
for (const w of words) {
|
|
164
|
+
if (typeof w !== "string") throw new CommentSettingsError(`${name} must be a list of words`);
|
|
165
|
+
const word = w.normalize("NFC").replace(/\s+/g, " ").trim();
|
|
166
|
+
const folded = foldForMatch(word);
|
|
167
|
+
if (word.length === 0 || folded.length === 0)
|
|
168
|
+
throw new CommentSettingsError(`${name} cannot hold an empty entry`);
|
|
169
|
+
if (word.length > MAX_WORD_LENGTH)
|
|
170
|
+
throw new CommentSettingsError(`${name} entries are at most ${MAX_WORD_LENGTH} characters`);
|
|
171
|
+
if (seen.has(folded)) continue;
|
|
172
|
+
seen.add(folded);
|
|
173
|
+
out.push(word);
|
|
174
|
+
}
|
|
175
|
+
return out;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Applies a patch to the current settings and checks the result. Throws `CommentSettingsError`
|
|
180
|
+
* for anything outside the allowed values; unknown keys are refused so a typo is not silently
|
|
181
|
+
* dropped.
|
|
182
|
+
*/
|
|
183
|
+
export function applySettingsInput(
|
|
184
|
+
current ,
|
|
185
|
+
input ,
|
|
186
|
+
) {
|
|
187
|
+
if (input === null || typeof input !== "object" || Array.isArray(input))
|
|
188
|
+
throw new CommentSettingsError("settings must be an object");
|
|
189
|
+
const known = new Set([
|
|
190
|
+
"enabled",
|
|
191
|
+
"showWhenOff",
|
|
192
|
+
"collections",
|
|
193
|
+
"closeAfterDays",
|
|
194
|
+
"protection",
|
|
195
|
+
"turnstileSiteKey",
|
|
196
|
+
"allowWithoutScript",
|
|
197
|
+
"allowWithoutScriptWithTurnstile",
|
|
198
|
+
"linkLimit",
|
|
199
|
+
"watchWords",
|
|
200
|
+
"blockedWords",
|
|
201
|
+
"dailyCap",
|
|
202
|
+
"aiLabels",
|
|
203
|
+
"retention",
|
|
204
|
+
"planHint",
|
|
205
|
+
]);
|
|
206
|
+
for (const k of Object.keys(input))
|
|
207
|
+
if (!known.has(k)) throw new CommentSettingsError(`unknown setting "${k}"`);
|
|
208
|
+
const bool = (name , fallback ) => {
|
|
209
|
+
const v = input[name];
|
|
210
|
+
if (v === undefined) return fallback;
|
|
211
|
+
if (typeof v !== "boolean") throw new CommentSettingsError(`${name} must be true or false`);
|
|
212
|
+
return v;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
let collections = current.collections;
|
|
216
|
+
if (input.collections !== undefined) {
|
|
217
|
+
const c = input.collections ;
|
|
218
|
+
if (c === null || typeof c !== "object" || Array.isArray(c))
|
|
219
|
+
throw new CommentSettingsError("collections must be an object");
|
|
220
|
+
const entries = Object.entries(c );
|
|
221
|
+
if (entries.length > MAX_COLLECTIONS)
|
|
222
|
+
throw new CommentSettingsError(`at most ${MAX_COLLECTIONS} collections`);
|
|
223
|
+
const out = {};
|
|
224
|
+
for (const [slug, v] of entries) {
|
|
225
|
+
if (!SLUG.test(slug) || slug.length > 64)
|
|
226
|
+
throw new CommentSettingsError(`"${slug.slice(0, 40)}" is not a collection slug`);
|
|
227
|
+
if (v === null || typeof v !== "object" || Array.isArray(v))
|
|
228
|
+
throw new CommentSettingsError(`collections.${slug} must be an object`);
|
|
229
|
+
const o = v ;
|
|
230
|
+
for (const k of Object.keys(o))
|
|
231
|
+
if (k !== "enabled" && k !== "closeAfterDays")
|
|
232
|
+
throw new CommentSettingsError(`unknown setting "collections.${slug}.${k}"`);
|
|
233
|
+
if (typeof o.enabled !== "boolean")
|
|
234
|
+
throw new CommentSettingsError(`collections.${slug}.enabled must be true or false`);
|
|
235
|
+
if (o.closeAfterDays !== undefined)
|
|
236
|
+
checkDays(`collections.${slug}.closeAfterDays`, o.closeAfterDays, true);
|
|
237
|
+
out[slug] =
|
|
238
|
+
o.closeAfterDays === undefined
|
|
239
|
+
? { enabled: o.enabled }
|
|
240
|
+
: { enabled: o.enabled, closeAfterDays: o.closeAfterDays };
|
|
241
|
+
}
|
|
242
|
+
collections = out;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const closeAfterDays =
|
|
246
|
+
input.closeAfterDays === undefined ? current.closeAfterDays : input.closeAfterDays;
|
|
247
|
+
checkDays("closeAfterDays", closeAfterDays, true);
|
|
248
|
+
|
|
249
|
+
const protection = input.protection ?? current.protection;
|
|
250
|
+
if (protection !== "pow" && protection !== "turnstile")
|
|
251
|
+
throw new CommentSettingsError('protection must be "pow" or "turnstile"');
|
|
252
|
+
const turnstileSiteKey =
|
|
253
|
+
input.turnstileSiteKey === undefined ? current.turnstileSiteKey : input.turnstileSiteKey;
|
|
254
|
+
if (
|
|
255
|
+
turnstileSiteKey !== null &&
|
|
256
|
+
(typeof turnstileSiteKey !== "string" || !SITE_KEY.test(turnstileSiteKey))
|
|
257
|
+
)
|
|
258
|
+
throw new CommentSettingsError("turnstileSiteKey must be a Turnstile site key");
|
|
259
|
+
if (protection === "turnstile" && turnstileSiteKey === null)
|
|
260
|
+
throw new CommentSettingsError("Turnstile needs its site key");
|
|
261
|
+
|
|
262
|
+
const linkLimit = input.linkLimit ?? current.linkLimit;
|
|
263
|
+
if (!isInt(linkLimit, 0, LINK_HARD_LIMIT))
|
|
264
|
+
throw new CommentSettingsError(`linkLimit must be a whole number from 0 to ${LINK_HARD_LIMIT}`);
|
|
265
|
+
const dailyCap = input.dailyCap ?? current.dailyCap;
|
|
266
|
+
if (!isInt(dailyCap, 1, MAX_DAILY_CAP))
|
|
267
|
+
throw new CommentSettingsError(`dailyCap must be a whole number from 1 to ${MAX_DAILY_CAP}`);
|
|
268
|
+
const aiLabels = input.aiLabels ?? current.aiLabels;
|
|
269
|
+
if (aiLabels !== "off" && aiLabels !== "workers-ai")
|
|
270
|
+
throw new CommentSettingsError('aiLabels must be "off" or "workers-ai"');
|
|
271
|
+
const planHint = input.planHint === undefined ? current.planHint : input.planHint;
|
|
272
|
+
if (planHint !== null && planHint !== "free" && planHint !== "paid")
|
|
273
|
+
throw new CommentSettingsError('planHint must be "free", "paid" or null');
|
|
274
|
+
|
|
275
|
+
let retention = current.retention;
|
|
276
|
+
if (input.retention !== undefined) {
|
|
277
|
+
const r = input.retention ;
|
|
278
|
+
if (r === null || typeof r !== "object" || Array.isArray(r))
|
|
279
|
+
throw new CommentSettingsError("retention must be an object");
|
|
280
|
+
for (const k of Object.keys(r))
|
|
281
|
+
if (!(k in DEFAULT_RETENTION))
|
|
282
|
+
throw new CommentSettingsError(`unknown setting "retention.${k}"`);
|
|
283
|
+
retention = { ...current.retention, ...(r ) };
|
|
284
|
+
checkDays("retention.pendingDays", retention.pendingDays, false);
|
|
285
|
+
checkDays("retention.spamDays", retention.spamDays, false);
|
|
286
|
+
checkDays("retention.deletedDays", retention.deletedDays, false);
|
|
287
|
+
checkDays("retention.hiddenDays", retention.hiddenDays, true);
|
|
288
|
+
checkDays("retention.clientDataDays", retention.clientDataDays, false, MAX_CLIENT_DATA_DAYS);
|
|
289
|
+
checkDays("retention.resolvedReportDays", retention.resolvedReportDays, false);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return {
|
|
293
|
+
...current,
|
|
294
|
+
enabled: bool("enabled", current.enabled),
|
|
295
|
+
showWhenOff: bool("showWhenOff", current.showWhenOff),
|
|
296
|
+
collections,
|
|
297
|
+
closeAfterDays,
|
|
298
|
+
protection,
|
|
299
|
+
turnstileSiteKey,
|
|
300
|
+
allowWithoutScript: bool("allowWithoutScript", current.allowWithoutScript),
|
|
301
|
+
allowWithoutScriptWithTurnstile: bool(
|
|
302
|
+
"allowWithoutScriptWithTurnstile",
|
|
303
|
+
current.allowWithoutScriptWithTurnstile,
|
|
304
|
+
),
|
|
305
|
+
linkLimit,
|
|
306
|
+
watchWords:
|
|
307
|
+
input.watchWords === undefined
|
|
308
|
+
? current.watchWords
|
|
309
|
+
: normalizeWordList("watchWords", input.watchWords),
|
|
310
|
+
blockedWords:
|
|
311
|
+
input.blockedWords === undefined
|
|
312
|
+
? current.blockedWords
|
|
313
|
+
: normalizeWordList("blockedWords", input.blockedWords),
|
|
314
|
+
dailyCap,
|
|
315
|
+
aiLabels,
|
|
316
|
+
retention,
|
|
317
|
+
planHint,
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Whether posts without JavaScript (no proof of work, no Turnstile token) are accepted (§6.2 step
|
|
323
|
+
* 7, D11): when the owner allows them, and, while Turnstile is on, only when the owner allowed them
|
|
324
|
+
* under Turnstile as well.
|
|
325
|
+
*/
|
|
326
|
+
export function withoutScriptAllowed(
|
|
327
|
+
settings
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
,
|
|
331
|
+
) {
|
|
332
|
+
return (
|
|
333
|
+
settings.allowWithoutScript &&
|
|
334
|
+
(settings.protection !== "turnstile" || settings.allowWithoutScriptWithTurnstile)
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/** Whether new comments are accepted in a collection (site and collection both on). */
|
|
339
|
+
export function collectionEnabled(settings , collection ) {
|
|
340
|
+
return settings.enabled && settings.collections[collection]?.enabled === true;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** Days after first publication a thread in this collection closes (`null` = never). */
|
|
344
|
+
export function closeAfterDaysFor(settings , collection ) {
|
|
345
|
+
const c = settings.collections[collection];
|
|
346
|
+
return c?.closeAfterDays === undefined ? settings.closeAfterDays : c.closeAfterDays;
|
|
347
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @cloudhal/comments/sql — `SqlCommentStore` over `SqlDriver` (SQLite locally and on Node, D1 on
|
|
3
|
+
* Cloudflare) for the tables of migration `0016_comments`. Worker-safe.
|
|
4
|
+
*/
|
|
5
|
+
export { type CommenterExportLine, CommentImportError, type CommentsExportHeader, type CommentsStatus, commentsStatus, EXPORT_PAGE_COMMENTERS, EXPORT_PAGE_COMMENTS, type ExportPage, exportHeader, exportPage, IMPORT_MAX_LINES, type ImportProblem, type ImportReport, importLines, PARENT_MISSING, } from "./portability.js";
|
|
6
|
+
export { type CommentRow, toComment, toSettings } from "./rows.js";
|
|
7
|
+
export { type BanInput, type CommentSummaryStats, type PutThreadOptions, SqlCommentStore, type SqlCommentStoreOptions, } from "./store.js";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @cloudhal/comments/sql — `SqlCommentStore` over `SqlDriver` (SQLite locally and on Node, D1 on
|
|
3
|
+
* Cloudflare) for the tables of migration `0016_comments`. Worker-safe.
|
|
4
|
+
*/
|
|
5
|
+
export {
|
|
6
|
+
|
|
7
|
+
CommentImportError,
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
commentsStatus,
|
|
11
|
+
EXPORT_PAGE_COMMENTERS,
|
|
12
|
+
EXPORT_PAGE_COMMENTS,
|
|
13
|
+
|
|
14
|
+
exportHeader,
|
|
15
|
+
exportPage,
|
|
16
|
+
IMPORT_MAX_LINES,
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
importLines,
|
|
20
|
+
PARENT_MISSING,
|
|
21
|
+
} from "./portability.js";
|
|
22
|
+
export { toComment, toSettings } from "./rows.js";
|
|
23
|
+
export {
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
SqlCommentStore,
|
|
28
|
+
|
|
29
|
+
} from "./store.js";
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { CommentKeys } from "../crypto.js";
|
|
2
|
+
import { type CommentCounts } from "../model.js";
|
|
3
|
+
import type { SqlCommentStore } from "./store.js";
|
|
4
|
+
/** The first line of an export file. */
|
|
5
|
+
export interface CommentsExportHeader {
|
|
6
|
+
readonly cloudhal: "comments";
|
|
7
|
+
readonly version: 1;
|
|
8
|
+
readonly siteId: string;
|
|
9
|
+
readonly exportedAt: string;
|
|
10
|
+
readonly personalData?: true;
|
|
11
|
+
}
|
|
12
|
+
/** A personal-data line (only with `personal`). */
|
|
13
|
+
export interface CommenterExportLine {
|
|
14
|
+
readonly commenter: {
|
|
15
|
+
readonly commenterId: string;
|
|
16
|
+
readonly email: string;
|
|
17
|
+
readonly firstSeen: string;
|
|
18
|
+
readonly commentIds: readonly string[];
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export declare const exportHeader: (siteId: string, exportedAt: string, personal?: boolean) => CommentsExportHeader;
|
|
22
|
+
/** Comments per export page: 10 indexed reads of 50. */
|
|
23
|
+
export declare const EXPORT_PAGE_COMMENTS = 500;
|
|
24
|
+
/** Commenters per export page: four reads for the whole page (`SqlCommentStore.commenters`). */
|
|
25
|
+
export declare const EXPORT_PAGE_COMMENTERS = 100;
|
|
26
|
+
/** Lines one import call accepts (the CLI sends batches of this size or less). */
|
|
27
|
+
export declare const IMPORT_MAX_LINES = 200;
|
|
28
|
+
export interface ExportPage {
|
|
29
|
+
/** JSON lines without trailing newlines (the header only on the first page). */
|
|
30
|
+
readonly lines: string[];
|
|
31
|
+
/** Pass back as `cursor` for the next page; absent when the export is complete. */
|
|
32
|
+
readonly next?: string;
|
|
33
|
+
readonly comments: number;
|
|
34
|
+
readonly commenters: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* One page of a site's export. Without `cursor` the page starts with the header. With
|
|
38
|
+
* `personal`, commenter lines follow the comments (needs `keys`).
|
|
39
|
+
*/
|
|
40
|
+
export declare function exportPage(store: SqlCommentStore, siteId: string, o?: {
|
|
41
|
+
readonly cursor?: string | undefined;
|
|
42
|
+
readonly personal?: boolean | undefined;
|
|
43
|
+
readonly keys?: CommentKeys | undefined;
|
|
44
|
+
readonly now?: Date | undefined;
|
|
45
|
+
readonly maxComments?: number | undefined;
|
|
46
|
+
readonly maxCommenters?: number | undefined;
|
|
47
|
+
}): Promise<ExportPage>;
|
|
48
|
+
export declare class CommentImportError extends Error {
|
|
49
|
+
readonly name = "CommentImportError";
|
|
50
|
+
}
|
|
51
|
+
export interface ImportProblem {
|
|
52
|
+
/** 1-based line number within the lines given to this call. */
|
|
53
|
+
readonly line: number;
|
|
54
|
+
readonly id?: string;
|
|
55
|
+
readonly error: string;
|
|
56
|
+
}
|
|
57
|
+
export interface ImportReport {
|
|
58
|
+
/** Comment records stored by this call. */
|
|
59
|
+
readonly imported: number;
|
|
60
|
+
/** Records already there (same id, or same importer origin): nothing changed. */
|
|
61
|
+
readonly skipped: number;
|
|
62
|
+
/** Commenter lines whose address was stored or linked. */
|
|
63
|
+
readonly commenters: number;
|
|
64
|
+
/** Lines refused, with why (the rest of the call still applies). */
|
|
65
|
+
readonly invalid: readonly ImportProblem[];
|
|
66
|
+
/** Entries whose comments tag was queued for a purge (new approved comments). */
|
|
67
|
+
readonly purged: readonly string[];
|
|
68
|
+
}
|
|
69
|
+
/** The refusal a caller may retry once the rest of the file is in (a parent in a later call). */
|
|
70
|
+
export declare const PARENT_MISSING = "the parent comment is not stored for this entry";
|
|
71
|
+
/**
|
|
72
|
+
* Imports JSON lines into a site (see the module comment). `entries` answers which node ids are
|
|
73
|
+
* content entries of the site. At most `IMPORT_MAX_LINES` lines per call.
|
|
74
|
+
*/
|
|
75
|
+
export declare function importLines(store: SqlCommentStore, siteId: string, input: readonly string[], o: {
|
|
76
|
+
readonly entries: (nodeIds: readonly string[]) => Promise<ReadonlySet<string>>;
|
|
77
|
+
readonly keys?: CommentKeys | undefined;
|
|
78
|
+
readonly now?: Date | undefined;
|
|
79
|
+
}): Promise<ImportReport>;
|
|
80
|
+
/** What `cloudhal comments status` shows (RFC-0007 §15.4): counts and budgets, never reader text. */
|
|
81
|
+
export interface CommentsStatus {
|
|
82
|
+
readonly siteId: string;
|
|
83
|
+
readonly settings: {
|
|
84
|
+
readonly enabled: boolean;
|
|
85
|
+
readonly collections: readonly string[];
|
|
86
|
+
readonly protection: "pow" | "turnstile";
|
|
87
|
+
readonly allowWithoutScript: boolean;
|
|
88
|
+
readonly closeAfterDays: number | null;
|
|
89
|
+
/** The settings row exists (else: the defaults, comments off). */
|
|
90
|
+
readonly stored: boolean;
|
|
91
|
+
};
|
|
92
|
+
readonly counts: CommentCounts;
|
|
93
|
+
readonly pending: {
|
|
94
|
+
readonly count: number;
|
|
95
|
+
readonly oldestAt: string | null;
|
|
96
|
+
};
|
|
97
|
+
/** Today's (UTC) stored guest submissions against the daily cap (§6.5). */
|
|
98
|
+
readonly today: {
|
|
99
|
+
readonly stored: number;
|
|
100
|
+
readonly withoutScript: number;
|
|
101
|
+
readonly cap: number;
|
|
102
|
+
readonly paused: boolean;
|
|
103
|
+
};
|
|
104
|
+
/** The comment purge queue and the shared purge budget (§8.4). */
|
|
105
|
+
readonly purge: {
|
|
106
|
+
readonly queued: number;
|
|
107
|
+
readonly takedowns: number;
|
|
108
|
+
readonly oldestAt: string | null;
|
|
109
|
+
/** Purge requests (publishing and comments) in the last 60 s; Free allows 5 a minute. */
|
|
110
|
+
readonly lastMinute: number;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export declare function commentsStatus(store: SqlCommentStore, siteId: string, now?: Date): Promise<CommentsStatus>;
|