@cloudhal/comments 0.0.0-stage → 0.1.1

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.
Files changed (46) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +86 -2
  3. package/dist/src/client/comments.browser.js +245 -0
  4. package/dist/src/client/index.d.ts +19 -0
  5. package/dist/src/client/index.js +39 -0
  6. package/dist/src/client/solver.browser.js +118 -0
  7. package/dist/src/crypto.d.ts +64 -0
  8. package/dist/src/crypto.js +170 -0
  9. package/dist/src/errors.d.ts +38 -0
  10. package/dist/src/errors.js +61 -0
  11. package/dist/src/fixtures/comment-text.json +335 -0
  12. package/dist/src/hashes.d.ts +70 -0
  13. package/dist/src/hashes.js +191 -0
  14. package/dist/src/index.d.ts +24 -0
  15. package/dist/src/index.js +24 -0
  16. package/dist/src/limits.d.ts +73 -0
  17. package/dist/src/limits.js +227 -0
  18. package/dist/src/linkify.d.ts +53 -0
  19. package/dist/src/linkify.js +142 -0
  20. package/dist/src/model.d.ts +287 -0
  21. package/dist/src/model.js +341 -0
  22. package/dist/src/normalize.d.ts +17 -0
  23. package/dist/src/normalize.js +125 -0
  24. package/dist/src/pipeline.d.ts +176 -0
  25. package/dist/src/pipeline.js +898 -0
  26. package/dist/src/pow.d.ts +86 -0
  27. package/dist/src/pow.js +239 -0
  28. package/dist/src/purge.d.ts +87 -0
  29. package/dist/src/purge.js +186 -0
  30. package/dist/src/retention.d.ts +32 -0
  31. package/dist/src/retention.js +106 -0
  32. package/dist/src/rules.d.ts +68 -0
  33. package/dist/src/rules.js +218 -0
  34. package/dist/src/settings.d.ts +108 -0
  35. package/dist/src/settings.js +347 -0
  36. package/dist/src/sql/index.d.ts +7 -0
  37. package/dist/src/sql/index.js +29 -0
  38. package/dist/src/sql/portability.d.ts +113 -0
  39. package/dist/src/sql/portability.js +514 -0
  40. package/dist/src/sql/rows.d.ts +54 -0
  41. package/dist/src/sql/rows.js +145 -0
  42. package/dist/src/sql/store.d.ts +312 -0
  43. package/dist/src/sql/store.js +2111 -0
  44. package/dist/src/thread.d.ts +35 -0
  45. package/dist/src/thread.js +64 -0
  46. package/package.json +61 -3
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The effective state of an entry's thread (RFC-0007 §4.5) — one function used by the renderer,
3
+ * the site Worker and Studio so they never disagree:
4
+ *
5
+ * 1. `mode = hidden` → **hidden** (nothing rendered, nothing accepted).
6
+ * 2. The site or the entry's collection is off → **closed** when `showWhenOff` and approved
7
+ * comments exist, else **off**.
8
+ * 3. `mode = closed` → **closed**; `mode = open` → **open** unless an explicit `closesAt` passed.
9
+ * 4. `default`: closes at `closesAt` when set, else at first publication + `closeAfterDays`
10
+ * (the collection's, else the site's; `null` = never). Before that **open**, after **closed**.
11
+ */
12
+ import { type ThreadRow, type ThreadState } from "./model.js";
13
+ import { type CommentSettings } from "./settings.js";
14
+ export interface ThreadEntry {
15
+ readonly nodeId: string;
16
+ readonly collection: string;
17
+ /** The entry's first publication (`publishedAt`); `null` while never published. */
18
+ readonly publishedAt: string | null;
19
+ }
20
+ export interface ThreadStateInput {
21
+ readonly settings: CommentSettings;
22
+ readonly entry: ThreadEntry;
23
+ readonly thread?: Pick<ThreadRow, "mode" | "closesAt"> | null;
24
+ /** Whether approved comments exist (only rule 2 reads it). */
25
+ readonly hasApproved?: boolean;
26
+ readonly now: Date;
27
+ }
28
+ /**
29
+ * When the thread closes (or closed), as an ISO instant; `null` when it never closes by time.
30
+ * Explicit `closesAt` wins, else first publication + `closeAfterDays`.
31
+ */
32
+ export declare function threadClosesAt(settings: CommentSettings, entry: ThreadEntry, thread?: Pick<ThreadRow, "mode" | "closesAt"> | null): string | null;
33
+ export declare function threadState(input: ThreadStateInput): ThreadState;
34
+ /** Whether approved comments are rendered at all (open or closed threads). */
35
+ export declare const threadVisible: (state: ThreadState) => boolean;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * The effective state of an entry's thread (RFC-0007 §4.5) — one function used by the renderer,
3
+ * the site Worker and Studio so they never disagree:
4
+ *
5
+ * 1. `mode = hidden` → **hidden** (nothing rendered, nothing accepted).
6
+ * 2. The site or the entry's collection is off → **closed** when `showWhenOff` and approved
7
+ * comments exist, else **off**.
8
+ * 3. `mode = closed` → **closed**; `mode = open` → **open** unless an explicit `closesAt` passed.
9
+ * 4. `default`: closes at `closesAt` when set, else at first publication + `closeAfterDays`
10
+ * (the collection's, else the site's; `null` = never). Before that **open**, after **closed**.
11
+ */
12
+ import { DAY_MS, } from "./model.js";
13
+ import { closeAfterDaysFor, collectionEnabled } from "./settings.js";
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+ /**
32
+ * When the thread closes (or closed), as an ISO instant; `null` when it never closes by time.
33
+ * Explicit `closesAt` wins, else first publication + `closeAfterDays`.
34
+ */
35
+ export function threadClosesAt(
36
+ settings ,
37
+ entry ,
38
+ thread ,
39
+ ) {
40
+ if (thread?.closesAt) return thread.closesAt;
41
+ if (thread?.mode === "open" || thread?.mode === "closed" || thread?.mode === "hidden")
42
+ return null;
43
+ const days = closeAfterDaysFor(settings, entry.collection);
44
+ if (days === null || entry.publishedAt === null) return null;
45
+ const at = Date.parse(entry.publishedAt);
46
+ if (!Number.isFinite(at)) return null;
47
+ return new Date(at + days * DAY_MS).toISOString();
48
+ }
49
+
50
+ export function threadState(input ) {
51
+ const { settings, entry, thread, now } = input;
52
+ const mode = thread?.mode ?? "default";
53
+ if (mode === "hidden") return "hidden";
54
+ if (!collectionEnabled(settings, entry.collection))
55
+ return settings.showWhenOff && input.hasApproved === true ? "closed" : "off";
56
+ if (mode === "closed") return "closed";
57
+ const closesAt = threadClosesAt(settings, entry, thread);
58
+ if (closesAt !== null && Date.parse(closesAt) <= now.getTime()) return "closed";
59
+ return "open";
60
+ }
61
+
62
+ /** Whether approved comments are rendered at all (open or closed threads). */
63
+ export const threadVisible = (state ) =>
64
+ state === "open" || state === "closed";
package/package.json CHANGED
@@ -1,6 +1,64 @@
1
1
  {
2
2
  "name": "@cloudhal/comments",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "Cloudhal reader comments (RFC-0007): settings and thread state, text normalising and content rules, linkify, first-party proof of work, the submission pipeline, purge planner, retention plan and the SQLite/D1 store. Worker-safe.",
5
+ "license": "Apache-2.0",
6
+ "homepage": "https://cloudhal.dev",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/cloudhal-dev/cloudhal.git",
10
+ "directory": "packages/comments"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/cloudhal-dev/cloudhal/issues"
14
+ },
15
+ "type": "module",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/src/index.d.ts",
19
+ "default": "./dist/src/index.js"
20
+ },
21
+ "./sql": {
22
+ "types": "./dist/src/sql/index.d.ts",
23
+ "default": "./dist/src/sql/index.js"
24
+ },
25
+ "./client": {
26
+ "types": "./dist/src/client/index.d.ts",
27
+ "default": "./dist/src/client/index.js"
28
+ },
29
+ "./testing": {
30
+ "types": "./dist/src/testing.d.ts",
31
+ "default": "./dist/src/testing.js"
32
+ },
33
+ "./fixtures/*": "./dist/src/fixtures/*"
34
+ },
35
+ "files": [
36
+ "dist",
37
+ "README.md"
38
+ ],
39
+ "dependencies": {
40
+ "@cloudhal/core-contracts": "0.1.1",
41
+ "@cloudhal/core-ts": "0.1.1",
42
+ "@cloudhal/storage": "0.1.1"
43
+ },
44
+ "devDependencies": {
45
+ "@cloudflare/workers-types": "^5.20261007.1",
46
+ "@types/better-sqlite3": "^9.6.0",
47
+ "@types/node": "^26.6.5",
48
+ "better-sqlite3": "13.0.3",
49
+ "miniflare": "4.20260730.0",
50
+ "typescript": "7.0.2",
51
+ "vitest": "5.0.3"
52
+ },
53
+ "engines": {
54
+ "node": ">=24"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public"
58
+ },
59
+ "scripts": {
60
+ "typecheck": "tsc --noEmit -p tsconfig.json",
61
+ "test": "vitest run",
62
+ "check": "pnpm typecheck && pnpm test"
63
+ }
6
64
  }