@molecule/api-resource-comment 1.1.0 → 1.1.2

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 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-15T14:22:29.350Z
6
+ Generated: 2026-10-16T00:32:13.746Z
7
7
  -->
8
8
 
9
9
  # @molecule/api-resource-comment
@@ -86,20 +86,14 @@ interface CreateCommentInput {
86
86
  }
87
87
  ```
88
88
 
89
- #### `PaginatedResult`
89
+ #### `UpdateCommentInput`
90
90
 
91
- A paginated result set.
91
+ Input for updating an existing comment.
92
92
 
93
93
  ```typescript
94
- interface PaginatedResult<T> {
95
- /** The result items for the current page. */
96
- data: T[]
97
- /** Total number of matching items across all pages. */
98
- total: number
99
- /** Maximum number of results per page. */
100
- limit: number
101
- /** Number of results skipped. */
102
- offset: number
94
+ interface UpdateCommentInput {
95
+ /** The updated comment body text. */
96
+ body: string
103
97
  }
104
98
  ```
105
99
 
@@ -116,14 +110,20 @@ interface PaginationOptions {
116
110
  }
117
111
  ```
118
112
 
119
- #### `UpdateCommentInput`
113
+ #### `PaginatedResult`
120
114
 
121
- Input for updating an existing comment.
115
+ A paginated result set.
122
116
 
123
117
  ```typescript
124
- interface UpdateCommentInput {
125
- /** The updated comment body text. */
126
- body: string
118
+ interface PaginatedResult<T> {
119
+ /** The result items for the current page. */
120
+ data: T[]
121
+ /** Total number of matching items across all pages. */
122
+ total: number
123
+ /** Maximum number of results per page. */
124
+ limit: number
125
+ /** Number of results skipped. */
126
+ offset: number
127
127
  }
128
128
  ```
129
129
 
@@ -153,105 +153,104 @@ function commentCount(req: MoleculeRequest, res: MoleculeResponse): Promise<void
153
153
  - `req` — The request with `resourceType` and `resourceId` params.
154
154
  - `res` — The response object.
155
155
 
156
- #### `commentNumbers(commentIds)`
156
+ #### `create(req, res)`
157
157
 
158
- The numbers of the given comments, for listing them with their numbers.
159
- Comments without a number are left out of the map.
158
+ Creates a new comment on a resource.
160
159
 
161
160
  ```typescript
162
- function commentNumbers(commentIds: readonly string[]): Promise<Map<string, number>>
161
+ function create(req: MoleculeRequest, res: MoleculeResponse): Promise<void>
163
162
  ```
164
163
 
165
- - `commentIds` — The comments' UUIDs.
166
-
167
- **Returns:** Each numbered comment's UUID mapped to its number.
164
+ - `req` — The request with `resourceType` and `resourceId` params and comment body.
165
+ - `res` — The response object.
168
166
 
169
- #### `create(req, res)`
167
+ #### `del(req, res)`
170
168
 
171
- Creates a new comment on a resource.
169
+ Deletes a comment. Only the comment owner can delete.
172
170
 
173
171
  ```typescript
174
- function create(req: MoleculeRequest, res: MoleculeResponse): Promise<void>
172
+ function del(req: MoleculeRequest, res: MoleculeResponse): Promise<void>
175
173
  ```
176
174
 
177
- - `req` — The request with `resourceType` and `resourceId` params and comment body.
175
+ - `req` — The request with `commentId` param.
178
176
  - `res` — The response object.
179
177
 
180
- #### `createComment(resourceType, resourceId, userId, data)`
178
+ #### `list(req, res)`
181
179
 
182
- Creates a new comment on a resource.
180
+ Lists paginated top-level comments for a resource.
183
181
 
184
182
  ```typescript
185
- function createComment(
186
- resourceType: string,
187
- resourceId: string,
188
- userId: string,
189
- data: CreateCommentInput,
190
- ): Promise<Comment>
183
+ function list(req: MoleculeRequest, res: MoleculeResponse): Promise<void>
191
184
  ```
192
185
 
193
- - `resourceType` — The type of resource being commented on.
194
- - `resourceId` — The ID of the resource being commented on.
195
- - `userId` — The ID of the commenting user.
196
- - `data` — The comment creation input.
197
-
198
- **Returns:** The created comment.
186
+ - `req` — The request with `resourceType` and `resourceId` params.
187
+ - `res` — The response object.
199
188
 
200
- #### `createNumberedComment(resourceType, resourceId, userId, data)`
189
+ #### `read(req, res)`
201
190
 
202
- Creates a comment and its number together: both are written, or neither.
191
+ Retrieves a single comment by ID.
203
192
 
204
193
  ```typescript
205
- function createNumberedComment(
206
- resourceType: string,
207
- resourceId: string,
208
- userId: string,
209
- data: CreateCommentInput,
210
- ): Promise<NumberedComment>
194
+ function read(req: MoleculeRequest, res: MoleculeResponse): Promise<void>
211
195
  ```
212
196
 
213
- - `resourceType` — The type of resource being commented on.
214
- - `resourceId` — The ID of the resource being commented on.
215
- - `userId` — The ID of the commenting user.
216
- - `data` — The comment creation input.
217
-
218
- **Returns:** The created comment with its number.
197
+ - `req` — The request with `commentId` param.
198
+ - `res` — The response object.
219
199
 
220
- #### `del(req, res)`
200
+ #### `replies(req, res)`
221
201
 
222
- Deletes a comment. Only the comment owner can delete.
202
+ Lists paginated replies to a comment.
223
203
 
224
204
  ```typescript
225
- function del(req: MoleculeRequest, res: MoleculeResponse): Promise<void>
205
+ function replies(req: MoleculeRequest, res: MoleculeResponse): Promise<void>
226
206
  ```
227
207
 
228
208
  - `req` — The request with `commentId` param.
229
209
  - `res` — The response object.
230
210
 
231
- #### `deleteComment(commentId, userId)`
211
+ #### `update(req, res)`
232
212
 
233
- Deletes a comment. Only the comment owner can delete.
213
+ Updates an existing comment. Only the comment owner can update.
234
214
 
235
215
  ```typescript
236
- function deleteComment(commentId: string, userId: string): Promise<boolean>
216
+ function update(req: MoleculeRequest, res: MoleculeResponse): Promise<void>
237
217
  ```
238
218
 
239
- - `commentId` — The comment ID to delete.
240
- - `userId` — The requesting user's ID (must match comment owner).
219
+ - `req` — The request with `commentId` param and update body.
220
+ - `res` — The response object.
241
221
 
242
- **Returns:** `true` if deleted, `false` if not found or unauthorized.
222
+ #### `numberComment(commentId)`
243
223
 
244
- #### `getCommentById(commentId)`
224
+ The comment's number, allocating the next one when it has none. Numbers are
225
+ unique and increase.
245
226
 
246
- Retrieves a single comment by ID.
227
+ ```typescript
228
+ function numberComment(commentId: string): Promise<number>
229
+ ```
230
+
231
+ - `commentId` — The comment's UUID.
232
+
233
+ **Returns:** Its sequential number.
234
+
235
+ #### `createNumberedComment(resourceType, resourceId, userId, data)`
236
+
237
+ Creates a comment and its number together: both are written, or neither.
247
238
 
248
239
  ```typescript
249
- function getCommentById(commentId: string): Promise<Comment | null>
240
+ function createNumberedComment(
241
+ resourceType: string,
242
+ resourceId: string,
243
+ userId: string,
244
+ data: CreateCommentInput,
245
+ ): Promise<NumberedComment>
250
246
  ```
251
247
 
252
- - `commentId` — The comment ID to look up.
248
+ - `resourceType` — The type of resource being commented on.
249
+ - `resourceId` — The ID of the resource being commented on.
250
+ - `userId` — The ID of the commenting user.
251
+ - `data` — The comment creation input.
253
252
 
254
- **Returns:** The comment or `null` if not found.
253
+ **Returns:** The created comment with its number.
255
254
 
256
255
  #### `getCommentByNumber(number)`
257
256
 
@@ -265,18 +264,38 @@ function getCommentByNumber(number: number): Promise<NumberedComment | null>
265
264
 
266
265
  **Returns:** The comment with its number, or `null` when no comment has it.
267
266
 
268
- #### `getCommentCount(resourceType, resourceId)`
267
+ #### `commentNumbers(commentIds)`
269
268
 
270
- Returns the total number of comments on a resource (including replies).
269
+ The numbers of the given comments, for listing them with their numbers.
270
+ Comments without a number are left out of the map.
271
271
 
272
272
  ```typescript
273
- function getCommentCount(resourceType: string, resourceId: string): Promise<number>
273
+ function commentNumbers(commentIds: readonly string[]): Promise<Map<string, number>>
274
274
  ```
275
275
 
276
- - `resourceType` — The type of resource.
277
- - `resourceId` — The ID of the resource.
276
+ - `commentIds` — The comments' UUIDs.
278
277
 
279
- **Returns:** The total comment count.
278
+ **Returns:** Each numbered comment's UUID mapped to its number.
279
+
280
+ #### `createComment(resourceType, resourceId, userId, data)`
281
+
282
+ Creates a new comment on a resource.
283
+
284
+ ```typescript
285
+ function createComment(
286
+ resourceType: string,
287
+ resourceId: string,
288
+ userId: string,
289
+ data: CreateCommentInput,
290
+ ): Promise<Comment>
291
+ ```
292
+
293
+ - `resourceType` — The type of resource being commented on.
294
+ - `resourceId` — The ID of the resource being commented on.
295
+ - `userId` — The ID of the commenting user.
296
+ - `data` — The comment creation input.
297
+
298
+ **Returns:** The created comment.
280
299
 
281
300
  #### `getCommentsByResource(resourceType, resourceId, options)`
282
301
 
@@ -297,110 +316,80 @@ function getCommentsByResource(
297
316
 
298
317
  **Returns:** A paginated result of comments.
299
318
 
300
- #### `getReplies(commentId, options)`
319
+ #### `getCommentById(commentId)`
301
320
 
302
- Retrieves paginated replies to a comment, ordered by creation date ascending.
321
+ Retrieves a single comment by ID.
303
322
 
304
323
  ```typescript
305
- function getReplies(
306
- commentId: string,
307
- options?: PaginationOptions,
308
- ): Promise<PaginatedResult<Comment>>
324
+ function getCommentById(commentId: string): Promise<Comment | null>
309
325
  ```
310
326
 
311
- - `commentId` — The parent comment ID.
312
- - `options` — Pagination options.
313
-
314
- **Returns:** A paginated result of reply comments.
315
-
316
- #### `list(req, res)`
317
-
318
- Lists paginated top-level comments for a resource.
319
-
320
- ```typescript
321
- function list(req: MoleculeRequest, res: MoleculeResponse): Promise<void>
322
- ```
327
+ - `commentId` — The comment ID to look up.
323
328
 
324
- - `req` — The request with `resourceType` and `resourceId` params.
325
- - `res` — The response object.
329
+ **Returns:** The comment or `null` if not found.
326
330
 
327
- #### `numberComment(commentId)`
331
+ #### `updateComment(commentId, userId, data)`
328
332
 
329
- The comment's number, allocating the next one when it has none. Numbers are
330
- unique and increase.
333
+ Updates a comment. Only the comment owner can update.
331
334
 
332
335
  ```typescript
333
- function numberComment(commentId: string): Promise<number>
336
+ function updateComment(
337
+ commentId: string,
338
+ userId: string,
339
+ data: UpdateCommentInput,
340
+ ): Promise<Comment | null>
334
341
  ```
335
342
 
336
- - `commentId` — The comment's UUID.
343
+ - `commentId` — The comment ID to update.
344
+ - `userId` — The requesting user's ID (must match comment owner).
345
+ - `data` — The update input.
337
346
 
338
- **Returns:** Its sequential number.
347
+ **Returns:** The updated comment or `null` if not found or unauthorized.
339
348
 
340
- #### `read(req, res)`
349
+ #### `deleteComment(commentId, userId)`
341
350
 
342
- Retrieves a single comment by ID.
351
+ Deletes a comment. Only the comment owner can delete.
343
352
 
344
353
  ```typescript
345
- function read(req: MoleculeRequest, res: MoleculeResponse): Promise<void>
354
+ function deleteComment(commentId: string, userId: string): Promise<boolean>
346
355
  ```
347
356
 
348
- - `req` — The request with `commentId` param.
349
- - `res` — The response object.
350
-
351
- #### `replies(req, res)`
352
-
353
- Lists paginated replies to a comment.
354
-
355
- ```typescript
356
- function replies(req: MoleculeRequest, res: MoleculeResponse): Promise<void>
357
- ```
357
+ - `commentId` — The comment ID to delete.
358
+ - `userId` — The requesting user's ID (must match comment owner).
358
359
 
359
- - `req` — The request with `commentId` param.
360
- - `res` — The response object.
360
+ **Returns:** `true` if deleted, `false` if not found or unauthorized.
361
361
 
362
- #### `update(req, res)`
362
+ #### `getReplies(commentId, options)`
363
363
 
364
- Updates an existing comment. Only the comment owner can update.
364
+ Retrieves paginated replies to a comment, ordered by creation date ascending.
365
365
 
366
366
  ```typescript
367
- function update(req: MoleculeRequest, res: MoleculeResponse): Promise<void>
367
+ function getReplies(
368
+ commentId: string,
369
+ options?: PaginationOptions,
370
+ ): Promise<PaginatedResult<Comment>>
368
371
  ```
369
372
 
370
- - `req` — The request with `commentId` param and update body.
371
- - `res` — The response object.
373
+ - `commentId` — The parent comment ID.
374
+ - `options` — Pagination options.
372
375
 
373
- #### `updateComment(commentId, userId, data)`
376
+ **Returns:** A paginated result of reply comments.
374
377
 
375
- Updates a comment. Only the comment owner can update.
378
+ #### `getCommentCount(resourceType, resourceId)`
379
+
380
+ Returns the total number of comments on a resource (including replies).
376
381
 
377
382
  ```typescript
378
- function updateComment(
379
- commentId: string,
380
- userId: string,
381
- data: UpdateCommentInput,
382
- ): Promise<Comment | null>
383
+ function getCommentCount(resourceType: string, resourceId: string): Promise<number>
383
384
  ```
384
385
 
385
- - `commentId` — The comment ID to update.
386
- - `userId` — The requesting user's ID (must match comment owner).
387
- - `data` — The update input.
386
+ - `resourceType` — The type of resource.
387
+ - `resourceId` — The ID of the resource.
388
388
 
389
- **Returns:** The updated comment or `null` if not found or unauthorized.
389
+ **Returns:** The total comment count.
390
390
 
391
391
  ### Constants
392
392
 
393
- #### `createCommentSchema`
394
-
395
- Schema for validating comment creation input.
396
-
397
- ```typescript
398
- const createCommentSchema: z.ZodObject<
399
- { body: z.ZodString; parentId: z.ZodOptional<z.ZodString> },
400
- z.core.$strip
401
- >
402
- ```
403
-
404
393
  #### `requestHandlerMap`
405
394
 
406
395
  Handler map for comment routes.
@@ -460,6 +449,17 @@ const routes: readonly [
460
449
  ]
461
450
  ```
462
451
 
452
+ #### `createCommentSchema`
453
+
454
+ Schema for validating comment creation input.
455
+
456
+ ```typescript
457
+ const createCommentSchema: z.ZodObject<
458
+ { body: z.ZodString; parentId: z.ZodOptional<z.ZodString> },
459
+ z.core.$strip
460
+ >
461
+ ```
462
+
463
463
  #### `updateCommentSchema`
464
464
 
465
465
  Schema for validating comment update input.
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAWH,OAAO,KAAK,EACV,OAAO,EACP,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,YAAY,CAAA;AAInB;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CACjC,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,OAAO,CAAC,CAUlB;AAED;;;;;;;;GAQG;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;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,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,wBAAsB,aAAa,CACjC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAczB;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAMvF;AAED;;;;;;GAMG;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
@@ -80,7 +80,9 @@ export async function updateComment(commentId, userId, data) {
80
80
  const result = await updateById(TABLE, commentId, {
81
81
  body: data.body,
82
82
  editedAt: new Date().toISOString(),
83
- updatedAt: new Date().toISOString(),
83
+ // Strictly later than the last write: an edit in the same millisecond as the create
84
+ // still shows a changed updatedAt.
85
+ updatedAt: new Date(Math.max(Date.now(), (Date.parse(String(existing.updatedAt ?? '')) || 0) + 1)).toISOString(),
84
86
  });
85
87
  return result.data;
86
88
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/api-resource-comment",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Threaded comments on any resource with polymorphic attachment and pagination",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -29,8 +29,8 @@
29
29
  ],
30
30
  "license": "Apache-2.0",
31
31
  "devDependencies": {
32
- "@molecule/api-database": "1.1.0",
33
- "@molecule/api-database-sqlite": "1.1.0",
32
+ "@molecule/api-database": "1.1.1",
33
+ "@molecule/api-database-sqlite": "1.2.2",
34
34
  "@types/node": "26.1.2",
35
35
  "typescript": "6.0.3",
36
36
  "vitest": "4.1.11",