@molecule/api-resource-comment 1.2.3 → 1.2.5
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 +11 -5
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/service.d.ts +6 -4
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +17 -7
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -11
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-
|
|
6
|
+
Generated: 2026-11-09T22:47:15.896Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/api-resource-comment
|
|
@@ -60,6 +60,8 @@ A comment attached to a resource, with optional threading via `parentId`.
|
|
|
60
60
|
interface Comment {
|
|
61
61
|
/** Unique comment identifier. */
|
|
62
62
|
id: string
|
|
63
|
+
/** Stable integer identity on creates and paginated reads; absent on unnumbered imports. */
|
|
64
|
+
number?: number
|
|
63
65
|
/** The type of resource this comment is attached to (e.g. 'project', 'post'). */
|
|
64
66
|
resourceType: string
|
|
65
67
|
/** The ID of the resource this comment is attached to. */
|
|
@@ -331,9 +333,10 @@ function createComment(
|
|
|
331
333
|
Retrieves paginated comments for a resource, ordered by creation date descending.
|
|
332
334
|
Only returns top-level comments (no replies).
|
|
333
335
|
|
|
334
|
-
The rows carry each comment's UUID `id
|
|
335
|
-
integer
|
|
336
|
-
|
|
336
|
+
The rows carry each comment's UUID `id` and its stable `number` when numbered.
|
|
337
|
+
An integer-addressed API returns that number as its external id, never the page
|
|
338
|
+
index. A raw import may have no number; call `numberComment(id)` explicitly
|
|
339
|
+
before exposing it through an integer-addressed API.
|
|
337
340
|
|
|
338
341
|
```typescript
|
|
339
342
|
function getCommentsByResource(
|
|
@@ -394,7 +397,8 @@ function deleteComment(commentId: string, userId: string): Promise<boolean>
|
|
|
394
397
|
|
|
395
398
|
#### `getReplies(commentId, options)`
|
|
396
399
|
|
|
397
|
-
Retrieves paginated replies to a comment, ordered by creation date ascending
|
|
400
|
+
Retrieves paginated replies to a comment, ordered by creation date ascending,
|
|
401
|
+
with each reply's stable `number` when numbered, like `getCommentsByResource`.
|
|
398
402
|
|
|
399
403
|
```typescript
|
|
400
404
|
function getReplies(
|
|
@@ -535,6 +539,8 @@ Peer dependencies:
|
|
|
535
539
|
- **Integer comment ids — every comment is numbered by default.** `createComment()`
|
|
536
540
|
writes the comment and its sequential `number` (1, 2, 3, …) together and returns both;
|
|
537
541
|
`createNumberedComment()` is the same create under the name an integer-id API reads best.
|
|
542
|
+
Paginated comments and replies also carry that stable `number`. Never derive an
|
|
543
|
+
identity from the page index: sorting, pagination and deletion change positions.
|
|
538
544
|
For an API whose clients address a comment by a stable integer,
|
|
539
545
|
return `number` as the id and read it back with
|
|
540
546
|
`getCommentByNumber(n)` — never hand-build an id from the UUID, and never read a missing
|
package/dist/index.d.ts
CHANGED
|
@@ -40,6 +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
|
+
* Paginated comments and replies also carry that stable `number`. Never derive an
|
|
44
|
+
* identity from the page index: sorting, pagination and deletion change positions.
|
|
43
45
|
* For an API whose clients address a comment by a stable integer,
|
|
44
46
|
* return `number` as the id and read it back with
|
|
45
47
|
* `getCommentByNumber(n)` — never hand-build an id from the UUID, and never read a missing
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsFG;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,6 +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
|
+
* Paginated comments and replies also carry that stable `number`. Never derive an
|
|
44
|
+
* identity from the page index: sorting, pagination and deletion change positions.
|
|
43
45
|
* For an API whose clients address a comment by a stable integer,
|
|
44
46
|
* return `number` as the id and read it back with
|
|
45
47
|
* `getCommentByNumber(n)` — never hand-build an id from the UUID, and never read a missing
|
package/dist/service.d.ts
CHANGED
|
@@ -35,9 +35,10 @@ export declare function createComment(resourceType: string, resourceId: string,
|
|
|
35
35
|
* Retrieves paginated comments for a resource, ordered by creation date descending.
|
|
36
36
|
* Only returns top-level comments (no replies).
|
|
37
37
|
*
|
|
38
|
-
* The rows carry each comment's UUID `id
|
|
39
|
-
* integer
|
|
40
|
-
*
|
|
38
|
+
* The rows carry each comment's UUID `id` and its stable `number` when numbered.
|
|
39
|
+
* An integer-addressed API returns that number as its external id, never the page
|
|
40
|
+
* index. A raw import may have no number; call `numberComment(id)` explicitly
|
|
41
|
+
* before exposing it through an integer-addressed API.
|
|
41
42
|
*
|
|
42
43
|
* @param resourceType - The type of resource.
|
|
43
44
|
* @param resourceId - The ID of the resource.
|
|
@@ -74,7 +75,8 @@ export declare function updateComment(commentId: string, userId: string, data: U
|
|
|
74
75
|
*/
|
|
75
76
|
export declare function deleteComment(commentId: string, userId: string): Promise<boolean>;
|
|
76
77
|
/**
|
|
77
|
-
* Retrieves paginated replies to a comment, ordered by creation date ascending
|
|
78
|
+
* Retrieves paginated replies to a comment, ordered by creation date ascending,
|
|
79
|
+
* with each reply's stable `number` when numbered, like `getCommentsByResource`.
|
|
78
80
|
*
|
|
79
81
|
* @param commentId - The parent comment ID.
|
|
80
82
|
* @param options - Pagination options.
|
package/dist/service.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAYH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,KAAK,EACV,OAAO,EACP,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAYH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,KAAK,EACV,OAAO,EACP,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,YAAY,CAAA;AAanB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,aAAa,CACjC,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,eAAe,CAAC,CAyB1B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,qBAAqB,CACzC,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAqBnC;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAE/E;AAED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CACjC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAczB;AAED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAMvF;AAED;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAC9B,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAiBnC;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAK/F"}
|
package/dist/service.js
CHANGED
|
@@ -7,8 +7,16 @@
|
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
9
|
import { count, create as dbCreate, deleteById, findById, findMany, updateById, } from '@molecule/api-database';
|
|
10
|
-
import { allocateCommentNumber } from './numbering.js';
|
|
10
|
+
import { allocateCommentNumber, numbersForComments } from './numbering.js';
|
|
11
11
|
const TABLE = 'comments';
|
|
12
|
+
/** Keep a page's stable integer identities beside its UUIDs without allocating on read. */
|
|
13
|
+
async function withNumbers(comments) {
|
|
14
|
+
const numbers = await numbersForComments(comments.map((comment) => comment.id));
|
|
15
|
+
return comments.map((comment) => {
|
|
16
|
+
const number = numbers.get(comment.id);
|
|
17
|
+
return number === undefined ? comment : { ...comment, number };
|
|
18
|
+
});
|
|
19
|
+
}
|
|
12
20
|
/**
|
|
13
21
|
* Creates a new comment on a resource, with its sequential number.
|
|
14
22
|
*
|
|
@@ -59,9 +67,10 @@ export async function createComment(resourceType, resourceId, userId, data) {
|
|
|
59
67
|
* Retrieves paginated comments for a resource, ordered by creation date descending.
|
|
60
68
|
* Only returns top-level comments (no replies).
|
|
61
69
|
*
|
|
62
|
-
* The rows carry each comment's UUID `id
|
|
63
|
-
* integer
|
|
64
|
-
*
|
|
70
|
+
* The rows carry each comment's UUID `id` and its stable `number` when numbered.
|
|
71
|
+
* An integer-addressed API returns that number as its external id, never the page
|
|
72
|
+
* index. A raw import may have no number; call `numberComment(id)` explicitly
|
|
73
|
+
* before exposing it through an integer-addressed API.
|
|
65
74
|
*
|
|
66
75
|
* @param resourceType - The type of resource.
|
|
67
76
|
* @param resourceId - The ID of the resource.
|
|
@@ -85,7 +94,7 @@ export async function getCommentsByResource(resourceType, resourceId, options =
|
|
|
85
94
|
}),
|
|
86
95
|
count(TABLE, where),
|
|
87
96
|
]);
|
|
88
|
-
return { data, total, limit, offset };
|
|
97
|
+
return { data: await withNumbers(data), total, limit, offset };
|
|
89
98
|
}
|
|
90
99
|
/**
|
|
91
100
|
* Retrieves a single comment by ID.
|
|
@@ -136,7 +145,8 @@ export async function deleteComment(commentId, userId) {
|
|
|
136
145
|
return true;
|
|
137
146
|
}
|
|
138
147
|
/**
|
|
139
|
-
* Retrieves paginated replies to a comment, ordered by creation date ascending
|
|
148
|
+
* Retrieves paginated replies to a comment, ordered by creation date ascending,
|
|
149
|
+
* with each reply's stable `number` when numbered, like `getCommentsByResource`.
|
|
140
150
|
*
|
|
141
151
|
* @param commentId - The parent comment ID.
|
|
142
152
|
* @param options - Pagination options.
|
|
@@ -155,7 +165,7 @@ export async function getReplies(commentId, options = {}) {
|
|
|
155
165
|
}),
|
|
156
166
|
count(TABLE, where),
|
|
157
167
|
]);
|
|
158
|
-
return { data, total, limit, offset };
|
|
168
|
+
return { data: await withNumbers(data), total, limit, offset };
|
|
159
169
|
}
|
|
160
170
|
/**
|
|
161
171
|
* Returns the total number of comments on a resource (including replies).
|
package/dist/types.d.ts
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
export interface Comment {
|
|
13
13
|
/** Unique comment identifier. */
|
|
14
14
|
id: string;
|
|
15
|
+
/** Stable integer identity on creates and paginated reads; absent on unnumbered imports. */
|
|
16
|
+
number?: number;
|
|
15
17
|
/** The type of resource this comment is attached to (e.g. 'project', 'post'). */
|
|
16
18
|
resourceType: string;
|
|
17
19
|
/** The ID of the resource this comment is attached to. */
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,iCAAiC;IACjC,EAAE,EAAE,MAAM,CAAA;IACV,iFAAiF;IACjF,YAAY,EAAE,MAAM,CAAA;IACpB,0DAA0D;IAC1D,UAAU,EAAE,MAAM,CAAA;IAClB,mDAAmD;IACnD,MAAM,EAAE,MAAM,CAAA;IACd,oFAAoF;IACpF,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,mEAAmE;IACnE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAA;IACjB,oDAAoD;IACpD,SAAS,EAAE,MAAM,CAAA;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,uDAAuD;IACvD,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,qCA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IAAI,EAAE,MAAM,CAAA;CACb;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,2CAA2C;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,iCAAiC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,6CAA6C;IAC7C,IAAI,EAAE,CAAC,EAAE,CAAA;IACT,uDAAuD;IACvD,KAAK,EAAE,MAAM,CAAA;IACb,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAA;IACb,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAA;CACf"}
|
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.5",
|
|
4
4
|
"description": "Threaded comments on any resource with polymorphic attachment and pagination",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"license": "Apache-2.0",
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@molecule/api-database": "1.2.2",
|
|
33
|
-
"@molecule/api-database-sqlite": "1.4.
|
|
33
|
+
"@molecule/api-database-sqlite": "1.4.3",
|
|
34
34
|
"@types/node": "26.6.5",
|
|
35
35
|
"typescript": "6.0.3",
|
|
36
36
|
"vitest": "4.1.12",
|
|
@@ -44,15 +44,6 @@
|
|
|
44
44
|
"zod": "^4.0.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependenciesMeta": {
|
|
47
|
-
"@molecule/api-database": {
|
|
48
|
-
"optional": true
|
|
49
|
-
},
|
|
50
|
-
"@molecule/api-i18n": {
|
|
51
|
-
"optional": true
|
|
52
|
-
},
|
|
53
|
-
"@molecule/api-logger": {
|
|
54
|
-
"optional": true
|
|
55
|
-
},
|
|
56
47
|
"@molecule/api-resource": {
|
|
57
48
|
"optional": true
|
|
58
49
|
}
|