@molecule/api-resource-comment 1.2.1 → 1.2.3
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/README.md +15 -6
- package/dist/index.d.ts +11 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -2
- package/dist/numbers.d.ts +1 -2
- package/dist/numbers.d.ts.map +1 -1
- package/dist/numbers.js +1 -2
- package/dist/service.d.ts +3 -3
- package/dist/service.js +3 -3
- package/package.json +6 -6
- package/src/__setup__/comment_numbers.sql +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-10-
|
|
6
|
+
Generated: 2026-10-31T12:45:29.246Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/api-resource-comment
|
|
@@ -301,8 +301,8 @@ Creates a new comment on a resource, with its sequential number.
|
|
|
301
301
|
|
|
302
302
|
The comment row and its `comment_numbers` row are written together: the
|
|
303
303
|
returned comment carries `number` (1, 2, 3, …) beside its UUID `id`. An API
|
|
304
|
-
whose clients address a comment by
|
|
305
|
-
|
|
304
|
+
whose clients address a comment by a stable integer
|
|
305
|
+
returns `number` as that id and reads it back with
|
|
306
306
|
`getCommentByNumber(number)` — never hand-build an id from the UUID.
|
|
307
307
|
`createNumberedComment()` is this same create under the name that path reads
|
|
308
308
|
best; `numberComment(id)` numbers a row that was inserted without this
|
|
@@ -387,7 +387,7 @@ Deletes a comment. Only the comment owner can delete.
|
|
|
387
387
|
function deleteComment(commentId: string, userId: string): Promise<boolean>
|
|
388
388
|
```
|
|
389
389
|
|
|
390
|
-
- `commentId` — The comment's UUID. To delete by the integer number an API
|
|
390
|
+
- `commentId` — The comment's UUID. To delete by the integer number an API exposes, look the row up with `getCommentByNumber(number)` and pass its `id`.
|
|
391
391
|
- `userId` — The requesting user's ID (must match comment owner).
|
|
392
392
|
|
|
393
393
|
**Returns:** `true` if deleted, `false` if not found or unauthorized.
|
|
@@ -535,8 +535,8 @@ Peer dependencies:
|
|
|
535
535
|
- **Integer comment ids — every comment is numbered by default.** `createComment()`
|
|
536
536
|
writes the comment and its sequential `number` (1, 2, 3, …) together and returns both;
|
|
537
537
|
`createNumberedComment()` is the same create under the name an integer-id API reads best.
|
|
538
|
-
For an API whose clients address a comment by
|
|
539
|
-
|
|
538
|
+
For an API whose clients address a comment by a stable integer,
|
|
539
|
+
return `number` as the id and read it back with
|
|
540
540
|
`getCommentByNumber(n)` — never hand-build an id from the UUID, and never read a missing
|
|
541
541
|
`commentNumbers(ids)` entry as `0` (a row inserted without `createComment()` has no number;
|
|
542
542
|
`numberComment(id)` gives it one). Never build your own id-mapping table.
|
|
@@ -552,6 +552,15 @@ Peer dependencies:
|
|
|
552
552
|
`resourceType`/`resourceId`): validate that the target exists in your domain
|
|
553
553
|
code if orphaned threads matter, and reuse the same canonical type slugs as
|
|
554
554
|
your other polymorphic resources (bookmarks, activity feed).
|
|
555
|
+
- **Client: address the thread with an identifier the page already has, not with the
|
|
556
|
+
loaded parent.** List and post with `/:resourceType/:resourceId/comments`, using the
|
|
557
|
+
parent identifier from the route when it is the one this API expects; when the route
|
|
558
|
+
carries something else (a slug where the API needs an id), resolve the id first and keep
|
|
559
|
+
the comment controls visibly disabled until it is known. Edit and delete a comment by its
|
|
560
|
+
own id (`PUT`/`DELETE /comments/:commentId`). A submit handler that starts with
|
|
561
|
+
`if (!parent) return` does nothing when the user submits before the parent finishes
|
|
562
|
+
loading: no request, no error, the text still in the box. Never let a click silently do
|
|
563
|
+
nothing.
|
|
555
564
|
|
|
556
565
|
## E2E Tests
|
|
557
566
|
|
package/dist/index.d.ts
CHANGED
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
* - **Integer comment ids — every comment is numbered by default.** `createComment()`
|
|
41
41
|
* writes the comment and its sequential `number` (1, 2, 3, …) together and returns both;
|
|
42
42
|
* `createNumberedComment()` is the same create under the name an integer-id API reads best.
|
|
43
|
-
* For an API whose clients address a comment by
|
|
44
|
-
*
|
|
43
|
+
* For an API whose clients address a comment by a stable integer,
|
|
44
|
+
* return `number` as the id and read it back with
|
|
45
45
|
* `getCommentByNumber(n)` — never hand-build an id from the UUID, and never read a missing
|
|
46
46
|
* `commentNumbers(ids)` entry as `0` (a row inserted without `createComment()` has no number;
|
|
47
47
|
* `numberComment(id)` gives it one). Never build your own id-mapping table.
|
|
@@ -57,6 +57,15 @@
|
|
|
57
57
|
* `resourceType`/`resourceId`): validate that the target exists in your domain
|
|
58
58
|
* code if orphaned threads matter, and reuse the same canonical type slugs as
|
|
59
59
|
* your other polymorphic resources (bookmarks, activity feed).
|
|
60
|
+
* - **Client: address the thread with an identifier the page already has, not with the
|
|
61
|
+
* loaded parent.** List and post with `/:resourceType/:resourceId/comments`, using the
|
|
62
|
+
* parent identifier from the route when it is the one this API expects; when the route
|
|
63
|
+
* carries something else (a slug where the API needs an id), resolve the id first and keep
|
|
64
|
+
* the comment controls visibly disabled until it is known. Edit and delete a comment by its
|
|
65
|
+
* own id (`PUT`/`DELETE /comments/:commentId`). A submit handler that starts with
|
|
66
|
+
* `if (!parent) return` does nothing when the user submits before the parent finishes
|
|
67
|
+
* loading: no request, no error, the text still in the box. Never let a click silently do
|
|
68
|
+
* nothing.
|
|
60
69
|
*
|
|
61
70
|
* @e2e
|
|
62
71
|
* Integration checklist — drive the real UI (live preview, no mocks), adapt
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoFG;AAEH,cAAc,wBAAwB,CAAA;AACtC,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,wBAAwB,CAAA;AACtC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
* - **Integer comment ids — every comment is numbered by default.** `createComment()`
|
|
41
41
|
* writes the comment and its sequential `number` (1, 2, 3, …) together and returns both;
|
|
42
42
|
* `createNumberedComment()` is the same create under the name an integer-id API reads best.
|
|
43
|
-
* For an API whose clients address a comment by
|
|
44
|
-
*
|
|
43
|
+
* For an API whose clients address a comment by a stable integer,
|
|
44
|
+
* return `number` as the id and read it back with
|
|
45
45
|
* `getCommentByNumber(n)` — never hand-build an id from the UUID, and never read a missing
|
|
46
46
|
* `commentNumbers(ids)` entry as `0` (a row inserted without `createComment()` has no number;
|
|
47
47
|
* `numberComment(id)` gives it one). Never build your own id-mapping table.
|
|
@@ -57,6 +57,15 @@
|
|
|
57
57
|
* `resourceType`/`resourceId`): validate that the target exists in your domain
|
|
58
58
|
* code if orphaned threads matter, and reuse the same canonical type slugs as
|
|
59
59
|
* your other polymorphic resources (bookmarks, activity feed).
|
|
60
|
+
* - **Client: address the thread with an identifier the page already has, not with the
|
|
61
|
+
* loaded parent.** List and post with `/:resourceType/:resourceId/comments`, using the
|
|
62
|
+
* parent identifier from the route when it is the one this API expects; when the route
|
|
63
|
+
* carries something else (a slug where the API needs an id), resolve the id first and keep
|
|
64
|
+
* the comment controls visibly disabled until it is known. Edit and delete a comment by its
|
|
65
|
+
* own id (`PUT`/`DELETE /comments/:commentId`). A submit handler that starts with
|
|
66
|
+
* `if (!parent) return` does nothing when the user submits before the parent finishes
|
|
67
|
+
* loading: no request, no error, the text still in the box. Never let a click silently do
|
|
68
|
+
* nothing.
|
|
60
69
|
*
|
|
61
70
|
* @e2e
|
|
62
71
|
* Integration checklist — drive the real UI (live preview, no mocks), adapt
|
package/dist/numbers.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Sequential integer numbers for comments, for APIs whose clients address a
|
|
3
|
-
* comment by an integer
|
|
4
|
-
* API specs). The comment keeps its UUID; the number lives in
|
|
3
|
+
* comment by an integer. The comment keeps its UUID; the number lives in
|
|
5
4
|
* `comment_numbers` and is allocated once, at most one per comment.
|
|
6
5
|
*
|
|
7
6
|
* **Numbering is the default create path:** `createComment()` writes the
|
package/dist/numbers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../src/numbers.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../src/numbers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAMH,OAAO,KAAK,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAK7D,qDAAqD;AACrD,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG;IACtC,4DAA4D;IAC5D,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAQD;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAEtE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,qBAAqB,CACzC,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,eAAe,CAAC,CAE1B;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAQxF;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,cAAc,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAEhG"}
|
package/dist/numbers.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Sequential integer numbers for comments, for APIs whose clients address a
|
|
3
|
-
* comment by an integer
|
|
4
|
-
* API specs). The comment keeps its UUID; the number lives in
|
|
3
|
+
* comment by an integer. The comment keeps its UUID; the number lives in
|
|
5
4
|
* `comment_numbers` and is allocated once, at most one per comment.
|
|
6
5
|
*
|
|
7
6
|
* **Numbering is the default create path:** `createComment()` writes the
|
package/dist/service.d.ts
CHANGED
|
@@ -13,8 +13,8 @@ import type { Comment, CreateCommentInput, PaginatedResult, PaginationOptions, U
|
|
|
13
13
|
*
|
|
14
14
|
* The comment row and its `comment_numbers` row are written together: the
|
|
15
15
|
* returned comment carries `number` (1, 2, 3, …) beside its UUID `id`. An API
|
|
16
|
-
* whose clients address a comment by
|
|
17
|
-
*
|
|
16
|
+
* whose clients address a comment by a stable integer
|
|
17
|
+
* returns `number` as that id and reads it back with
|
|
18
18
|
* `getCommentByNumber(number)` — never hand-build an id from the UUID.
|
|
19
19
|
* `createNumberedComment()` is this same create under the name that path reads
|
|
20
20
|
* best; `numberComment(id)` numbers a row that was inserted without this
|
|
@@ -67,7 +67,7 @@ export declare function updateComment(commentId: string, userId: string, data: U
|
|
|
67
67
|
* Deletes a comment. Only the comment owner can delete.
|
|
68
68
|
*
|
|
69
69
|
* @param commentId - The comment's UUID. To delete by the integer number an
|
|
70
|
-
* API
|
|
70
|
+
* API exposes, look the row up with
|
|
71
71
|
* `getCommentByNumber(number)` and pass its `id`.
|
|
72
72
|
* @param userId - The requesting user's ID (must match comment owner).
|
|
73
73
|
* @returns `true` if deleted, `false` if not found or unauthorized.
|
package/dist/service.js
CHANGED
|
@@ -14,8 +14,8 @@ const TABLE = 'comments';
|
|
|
14
14
|
*
|
|
15
15
|
* The comment row and its `comment_numbers` row are written together: the
|
|
16
16
|
* returned comment carries `number` (1, 2, 3, …) beside its UUID `id`. An API
|
|
17
|
-
* whose clients address a comment by
|
|
18
|
-
*
|
|
17
|
+
* whose clients address a comment by a stable integer
|
|
18
|
+
* returns `number` as that id and reads it back with
|
|
19
19
|
* `getCommentByNumber(number)` — never hand-build an id from the UUID.
|
|
20
20
|
* `createNumberedComment()` is this same create under the name that path reads
|
|
21
21
|
* best; `numberComment(id)` numbers a row that was inserted without this
|
|
@@ -123,7 +123,7 @@ export async function updateComment(commentId, userId, data) {
|
|
|
123
123
|
* Deletes a comment. Only the comment owner can delete.
|
|
124
124
|
*
|
|
125
125
|
* @param commentId - The comment's UUID. To delete by the integer number an
|
|
126
|
-
* API
|
|
126
|
+
* API exposes, look the row up with
|
|
127
127
|
* `getCommentByNumber(number)` and pass its `id`.
|
|
128
128
|
* @param userId - The requesting user's ID (must match comment owner).
|
|
129
129
|
* @returns `true` if deleted, `false` if not found or unauthorized.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/api-resource-comment",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "Threaded comments on any resource with polymorphic attachment and pagination",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
],
|
|
30
30
|
"license": "Apache-2.0",
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@molecule/api-database": "1.
|
|
33
|
-
"@molecule/api-database-sqlite": "1.
|
|
34
|
-
"@types/node": "26.
|
|
32
|
+
"@molecule/api-database": "1.2.2",
|
|
33
|
+
"@molecule/api-database-sqlite": "1.4.2",
|
|
34
|
+
"@types/node": "26.6.5",
|
|
35
35
|
"typescript": "6.0.3",
|
|
36
|
-
"vitest": "4.1.
|
|
37
|
-
"zod": "4.
|
|
36
|
+
"vitest": "4.1.12",
|
|
37
|
+
"zod": "4.6.7"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@molecule/api-database": "^1.1.0",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
-- Sequential integer numbers for comments, for APIs whose clients address a
|
|
2
|
-
-- comment by an integer id
|
|
2
|
+
-- comment by an integer id instead of its internal UUID.
|
|
3
3
|
-- createComment() / createNumberedComment() write this row with the comment;
|
|
4
4
|
-- numberComment(id) numbers a row that was inserted without them. The comment
|
|
5
5
|
-- keeps its UUID either way.
|