@molecule/api-resource-article 1.0.6 → 1.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/README.md CHANGED
@@ -3,15 +3,11 @@ 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-16T11:26:11.412Z
6
+ Generated: 2026-10-17T00:08:26.585Z
7
7
  -->
8
8
 
9
9
  # @molecule/api-resource-article
10
10
 
11
- > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
12
- > It is written to be read by coding agents as much as by people, and is generated from this
13
- > package's source — edit `src/index.ts` JSDoc, not this file.
14
-
15
11
  Articles and blog posts for molecule.dev.
16
12
 
17
13
  Articles with unique slugs, tags, favorites, a feed of the authors a user
@@ -21,6 +17,15 @@ docs site. Favorites are `@molecule/api-resource-reaction` reactions and the
21
17
  feed reads `@molecule/api-resource-follow`'s follows, so they are the same
22
18
  favorites and follows the rest of the app sees.
23
19
 
20
+ **Tables this package owns: `articles` and `article_tags`.** The join between them is
21
+ `article_tags.articleId` = `articles.id` (a declared FK, `ON DELETE CASCADE`; `("articleId", "tag")` is
22
+ unique, and `article_tags.position` is the order the tags were given in). It also ships
23
+ `reactions.sql` and `follows.sql`, which create the `reactions` and `follows` tables it reads by name.
24
+
25
+ > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
26
+ > It is written to be read by coding agents as much as by people, and is generated from this
27
+ > package's source — edit `src/index.ts` JSDoc, not this file.
28
+
24
29
  ## Quick Start
25
30
 
26
31
  ```typescript
@@ -30,7 +35,7 @@ import { routes, requestHandlerMap } from '@molecule/api-resource-article'
30
35
  // POST /articles create (signed in)
31
36
  // GET /articles ?tag= &author= &favoritedBy= &limit= &offset=
32
37
  // GET /articles/feed authors the signed-in user follows
33
- // GET /articles/tags tags in use, most-used first
38
+ // GET /articles/tags every tag in use, most-used first (?limit= caps it)
34
39
  // GET /articles/:slug
35
40
  // PUT /articles/:slug author only; a new title gives a new slug
36
41
  // DELETE /articles/:slug author only
@@ -52,6 +57,16 @@ const page = await listArticles({ tag: 'dragons', limit: 20, offset: 0, viewerId
52
57
  // page.data[0].favorited, page.data[0].favoritesCount, page.total
53
58
  ```
54
59
 
60
+ ```typescript
61
+ // RealWorld's `GET /api/tags` returns EVERY tag in use — that is `allTags()`,
62
+ // not `popularTags()`, whose default is the top 20:
63
+ import { allTags } from '@molecule/api-resource-article'
64
+
65
+ router.get('/api/tags', async (_req, res) => {
66
+ res.json({ tags: (await allTags()).map((tag) => tag.tag) })
67
+ })
68
+ ```
69
+
55
70
  ## Type
56
71
 
57
72
  `resource`
@@ -259,13 +274,16 @@ function feed(req: MoleculeRequest, res: MoleculeResponse): Promise<void>
259
274
 
260
275
  #### `tags(req, res)`
261
276
 
262
- `GET /articles/tags` — tags in use, most-used first (`?limit=`).
277
+ `GET /articles/tags` — every tag in use, most-used first.
278
+
279
+ With no `?limit=` this is the whole list, the shape RealWorld's `GET /tags`
280
+ asks for; `?limit=` narrows it to that many most-used tags.
263
281
 
264
282
  ```typescript
265
283
  function tags(req: MoleculeRequest, res: MoleculeResponse): Promise<void>
266
284
  ```
267
285
 
268
- - `req` — The request.
286
+ - `req` — The request; `?limit=` caps the list.
269
287
  - `res` — `[{ tag, count }]`.
270
288
 
271
289
  #### `read(req, res)`
@@ -426,17 +444,40 @@ function setFavorite(slug: string, userId: string, favorite: boolean): Promise<A
426
444
 
427
445
  **Returns:** The article after the change, or null when there is no such article.
428
446
 
447
+ #### `allTags()`
448
+
449
+ Every tag in use, most-used first (ties alphabetical).
450
+
451
+ This is the list a `GET /tags` endpoint returns, in the shape RealWorld's
452
+ `GET /api/tags` asks for: **all** of the tags in use, however many the
453
+ database holds. Use it for that endpoint — `popularTags` is the top-N
454
+ leaderboard and its default of 20 silently drops every tag past the
455
+ twentieth.
456
+
457
+ ```typescript
458
+ function allTags(): Promise<TagCount[]>
459
+ ```
460
+
461
+ **Returns:** Every tag in use, with its article count.
462
+
429
463
  #### `popularTags(limit)`
430
464
 
431
- Tags in use, most-used first.
465
+ The `limit` most-used tags, most-used first (ties alphabetical).
466
+
467
+ **This is a leaderboard, not "every tag".** The default is the top 20, so a
468
+ `GET /tags`-shaped endpoint that returns all tags in use (RealWorld's
469
+ `GET /api/tags`) must call `allTags` — or pass
470
+ `Number.POSITIVE_INFINITY` — or it silently drops every tag past the
471
+ twentieth once the database holds more than 20. Pass an explicit `limit`
472
+ when the caller really did ask for the N most-used, e.g. a sidebar of ten.
432
473
 
433
474
  ```typescript
434
475
  function popularTags(limit?: number): Promise<TagCount[]>
435
476
  ```
436
477
 
437
- - `limit` — How many to return (default 20).
478
+ - `limit` — How many tags to return, most-used first (default 20; `Number.POSITIVE_INFINITY` for every tag).
438
479
 
439
- **Returns:** Tags with their article counts.
480
+ **Returns:** The tags with their article counts.
440
481
 
441
482
  ### Constants
442
483
 
@@ -631,6 +672,13 @@ Peer dependencies:
631
672
  column (0-based). An app that reads the join table itself must order by
632
673
  `position` — a submission-order assertion (`tagList[0]`, `tagList[1]`) reads
633
674
  the wrong tag otherwise. `Article.tagList` is already in that order.
675
+ - **Tags: `allTags()` is every tag in use; `popularTags(limit)` is the top 20
676
+ by default.** A `GET /tags` endpoint (RealWorld's `GET /api/tags`, which
677
+ returns the whole list) built on `popularTags()` with no argument drops
678
+ every tag past the twentieth as soon as the database holds more than 20 —
679
+ call `allTags()` for that endpoint, and pass a `limit` only where the caller
680
+ asked for the N most-used. The package's own `GET /articles/tags` route does
681
+ exactly this: no `?limit=` is the whole list.
634
682
  - **Lists are newest first and paginated** — `{ data, total, limit, offset }`,
635
683
  at most 100 per page. `createdAt` is written with milliseconds, so two
636
684
  articles from the same second still come back in order on SQLite.
@@ -27,9 +27,12 @@ export declare function list(req: MoleculeRequest, res: MoleculeResponse): Promi
27
27
  */
28
28
  export declare function feed(req: MoleculeRequest, res: MoleculeResponse): Promise<void>;
29
29
  /**
30
- * `GET /articles/tags` — tags in use, most-used first (`?limit=`).
30
+ * `GET /articles/tags` — every tag in use, most-used first.
31
31
  *
32
- * @param req - The request.
32
+ * With no `?limit=` this is the whole list, the shape RealWorld's `GET /tags`
33
+ * asks for; `?limit=` narrows it to that many most-used tags.
34
+ *
35
+ * @param req - The request; `?limit=` caps the list.
33
36
  * @param res - `[{ tag, count }]`.
34
37
  */
35
38
  export declare function tags(req: MoleculeRequest, res: MoleculeResponse): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/handlers/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAwB/E;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAWvF;AAED;;;;;;GAMG;AACH,wBAAsB,IAAI,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBrF;AAED;;;;;GAKG;AACH,wBAAsB,IAAI,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAcrF;AAED;;;;;GAKG;AACH,wBAAsB,IAAI,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAOrF;AAED;;;;;GAKG;AACH,wBAAsB,IAAI,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CASrF;AAED;;;;;GAKG;AACH,wBAAsB,MAAM,C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AM,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAcvF;AAED;;;;;GAKG;AACH,wBAAsB,GAAG,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAYpF;AAiBD,yEAAyE;AACzE,eAAO,MAAM,QAAQ,QAdP,eAAe,OAAO,gBAAgB,KAAG,OAAO,CAAC,IAAI,CActB,CAAA;AAE7C,2EAA2E;AAC3E,eAAO,MAAM,UAAU,QAjBT,eAAe,OAAO,gBAAgB,KAAG,OAAO,CAAC,IAAI,CAiBnB,CAAA"}
@@ -4,7 +4,7 @@
4
4
  * @module
5
5
  */
6
6
  import { logger } from '@molecule/api-logger';
7
- import { createArticle, deleteArticle, getArticleBySlug, getFeed, listArticles, popularTags, setFavorite, updateArticle, } from '../service.js';
7
+ import { allTags, createArticle, deleteArticle, getArticleBySlug, getFeed, listArticles, popularTags, setFavorite, updateArticle, } from '../service.js';
8
8
  import { createArticleSchema, updateArticleSchema } from '../validation.js';
9
9
  import { failed, forbidden, invalid, notFound, queryInt, queryString, sessionUserId, unauthorized, } from './shared.js';
10
10
  /**
@@ -73,14 +73,18 @@ export async function feed(req, res) {
73
73
  }
74
74
  }
75
75
  /**
76
- * `GET /articles/tags` — tags in use, most-used first (`?limit=`).
76
+ * `GET /articles/tags` — every tag in use, most-used first.
77
77
  *
78
- * @param req - The request.
78
+ * With no `?limit=` this is the whole list, the shape RealWorld's `GET /tags`
79
+ * asks for; `?limit=` narrows it to that many most-used tags.
80
+ *
81
+ * @param req - The request; `?limit=` caps the list.
79
82
  * @param res - `[{ tag, count }]`.
80
83
  */
81
84
  export async function tags(req, res) {
82
85
  try {
83
- res.json(await popularTags(queryInt(req.query.limit)));
86
+ const limit = queryInt(req.query.limit);
87
+ res.json(limit === undefined ? await allTags() : await popularTags(limit));
84
88
  }
85
89
  catch (error) {
86
90
  logger.error('Failed to list article tags', { error });
package/dist/index.d.ts CHANGED
@@ -8,6 +8,11 @@
8
8
  * feed reads `@molecule/api-resource-follow`'s follows, so they are the same
9
9
  * favorites and follows the rest of the app sees.
10
10
  *
11
+ * **Tables this package owns: `articles` and `article_tags`.** The join between them is
12
+ * `article_tags.articleId` = `articles.id` (a declared FK, `ON DELETE CASCADE`; `("articleId", "tag")` is
13
+ * unique, and `article_tags.position` is the order the tags were given in). It also ships
14
+ * `reactions.sql` and `follows.sql`, which create the `reactions` and `follows` tables it reads by name.
15
+ *
11
16
  * @module
12
17
  * @example
13
18
  * ```typescript
@@ -17,7 +22,7 @@
17
22
  * // POST /articles create (signed in)
18
23
  * // GET /articles ?tag= &author= &favoritedBy= &limit= &offset=
19
24
  * // GET /articles/feed authors the signed-in user follows
20
- * // GET /articles/tags tags in use, most-used first
25
+ * // GET /articles/tags every tag in use, most-used first (?limit= caps it)
21
26
  * // GET /articles/:slug
22
27
  * // PUT /articles/:slug author only; a new title gives a new slug
23
28
  * // DELETE /articles/:slug author only
@@ -40,6 +45,17 @@
40
45
  * // page.data[0].favorited, page.data[0].favoritesCount, page.total
41
46
  * ```
42
47
  *
48
+ * @example
49
+ * ```typescript
50
+ * // RealWorld's `GET /api/tags` returns EVERY tag in use — that is `allTags()`,
51
+ * // not `popularTags()`, whose default is the top 20:
52
+ * import { allTags } from '@molecule/api-resource-article'
53
+ *
54
+ * router.get('/api/tags', async (_req, res) => {
55
+ * res.json({ tags: (await allTags()).map((tag) => tag.tag) })
56
+ * })
57
+ * ```
58
+ *
43
59
  * @remarks
44
60
  * - **Migration required: this package ships every table it reads, four in
45
61
  * all.** `articles.sql` creates the `articles` and `article_tags` tables;
@@ -59,6 +75,13 @@
59
75
  * column (0-based). An app that reads the join table itself must order by
60
76
  * `position` — a submission-order assertion (`tagList[0]`, `tagList[1]`) reads
61
77
  * the wrong tag otherwise. `Article.tagList` is already in that order.
78
+ * - **Tags: `allTags()` is every tag in use; `popularTags(limit)` is the top 20
79
+ * by default.** A `GET /tags` endpoint (RealWorld's `GET /api/tags`, which
80
+ * returns the whole list) built on `popularTags()` with no argument drops
81
+ * every tag past the twentieth as soon as the database holds more than 20 —
82
+ * call `allTags()` for that endpoint, and pass a `limit` only where the caller
83
+ * asked for the N most-used. The package's own `GET /articles/tags` route does
84
+ * exactly this: no `?limit=` is the whole list.
62
85
  * - **Lists are newest first and paginated** — `{ data, total, limit, offset }`,
63
86
  * at most 100 per page. `createdAt` is written with milliseconds, so two
64
87
  * articles from the same second still come back in order on SQLite.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2FG;AAEH,cAAc,wBAAwB,CAAA;AACtC,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA;AACtC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkHG;AAEH,cAAc,wBAAwB,CAAA;AACtC,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA;AACtC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA"}
package/dist/index.js CHANGED
@@ -8,6 +8,11 @@
8
8
  * feed reads `@molecule/api-resource-follow`'s follows, so they are the same
9
9
  * favorites and follows the rest of the app sees.
10
10
  *
11
+ * **Tables this package owns: `articles` and `article_tags`.** The join between them is
12
+ * `article_tags.articleId` = `articles.id` (a declared FK, `ON DELETE CASCADE`; `("articleId", "tag")` is
13
+ * unique, and `article_tags.position` is the order the tags were given in). It also ships
14
+ * `reactions.sql` and `follows.sql`, which create the `reactions` and `follows` tables it reads by name.
15
+ *
11
16
  * @module
12
17
  * @example
13
18
  * ```typescript
@@ -17,7 +22,7 @@
17
22
  * // POST /articles create (signed in)
18
23
  * // GET /articles ?tag= &author= &favoritedBy= &limit= &offset=
19
24
  * // GET /articles/feed authors the signed-in user follows
20
- * // GET /articles/tags tags in use, most-used first
25
+ * // GET /articles/tags every tag in use, most-used first (?limit= caps it)
21
26
  * // GET /articles/:slug
22
27
  * // PUT /articles/:slug author only; a new title gives a new slug
23
28
  * // DELETE /articles/:slug author only
@@ -40,6 +45,17 @@
40
45
  * // page.data[0].favorited, page.data[0].favoritesCount, page.total
41
46
  * ```
42
47
  *
48
+ * @example
49
+ * ```typescript
50
+ * // RealWorld's `GET /api/tags` returns EVERY tag in use — that is `allTags()`,
51
+ * // not `popularTags()`, whose default is the top 20:
52
+ * import { allTags } from '@molecule/api-resource-article'
53
+ *
54
+ * router.get('/api/tags', async (_req, res) => {
55
+ * res.json({ tags: (await allTags()).map((tag) => tag.tag) })
56
+ * })
57
+ * ```
58
+ *
43
59
  * @remarks
44
60
  * - **Migration required: this package ships every table it reads, four in
45
61
  * all.** `articles.sql` creates the `articles` and `article_tags` tables;
@@ -59,6 +75,13 @@
59
75
  * column (0-based). An app that reads the join table itself must order by
60
76
  * `position` — a submission-order assertion (`tagList[0]`, `tagList[1]`) reads
61
77
  * the wrong tag otherwise. `Article.tagList` is already in that order.
78
+ * - **Tags: `allTags()` is every tag in use; `popularTags(limit)` is the top 20
79
+ * by default.** A `GET /tags` endpoint (RealWorld's `GET /api/tags`, which
80
+ * returns the whole list) built on `popularTags()` with no argument drops
81
+ * every tag past the twentieth as soon as the database holds more than 20 —
82
+ * call `allTags()` for that endpoint, and pass a `limit` only where the caller
83
+ * asked for the N most-used. The package's own `GET /articles/tags` route does
84
+ * exactly this: no `?limit=` is the whole list.
62
85
  * - **Lists are newest first and paginated** — `{ data, total, limit, offset }`,
63
86
  * at most 100 per page. `createdAt` is written with milliseconds, so two
64
87
  * articles from the same second still come back in order on SQLite.
package/dist/service.d.ts CHANGED
@@ -108,10 +108,29 @@ export declare function deleteArticle(slug: string, userId: string): Promise<Aut
108
108
  */
109
109
  export declare function setFavorite(slug: string, userId: string, favorite: boolean): Promise<Article | null>;
110
110
  /**
111
- * Tags in use, most-used first.
111
+ * Every tag in use, most-used first (ties alphabetical).
112
112
  *
113
- * @param limit - How many to return (default 20).
114
- * @returns Tags with their article counts.
113
+ * This is the list a `GET /tags` endpoint returns, in the shape RealWorld's
114
+ * `GET /api/tags` asks for: **all** of the tags in use, however many the
115
+ * database holds. Use it for that endpoint — `popularTags` is the top-N
116
+ * leaderboard and its default of 20 silently drops every tag past the
117
+ * twentieth.
118
+ *
119
+ * @returns Every tag in use, with its article count.
120
+ */
121
+ export declare function allTags(): Promise<TagCount[]>;
122
+ /**
123
+ * The `limit` most-used tags, most-used first (ties alphabetical).
124
+ *
125
+ * **This is a leaderboard, not "every tag".** The default is the top 20, so a
126
+ * `GET /tags`-shaped endpoint that returns all tags in use (RealWorld's
127
+ * `GET /api/tags`) must call `allTags` — or pass
128
+ * `Number.POSITIVE_INFINITY` — or it silently drops every tag past the
129
+ * twentieth once the database holds more than 20. Pass an explicit `limit`
130
+ * when the caller really did ask for the N most-used, e.g. a sidebar of ten.
131
+ *
132
+ * @param limit - How many tags to return, most-used first (default 20; `Number.POSITIVE_INFINITY` for every tag).
133
+ * @returns The tags with their article counts.
115
134
  */
116
135
  export declare function popularTags(limit?: number): Promise<TagCount[]>;
117
136
  //# sourceMappingURL=service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":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AAC,CAAC,CAkBhC;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAW7F;AAED;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,OAAO,GAChB,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAOzB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,OAAO,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,CAEnD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,WAAW,CAAC,KAAK,SAAK,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAEjE"}
package/dist/service.js CHANGED
@@ -353,12 +353,41 @@ export async function setFavorite(slug, userId, favorite) {
353
353
  return article;
354
354
  }
355
355
  /**
356
- * Tags in use, most-used first.
356
+ * Every tag in use, most-used first (ties alphabetical).
357
357
  *
358
- * @param limit - How many to return (default 20).
359
- * @returns Tags with their article counts.
358
+ * This is the list a `GET /tags` endpoint returns, in the shape RealWorld's
359
+ * `GET /api/tags` asks for: **all** of the tags in use, however many the
360
+ * database holds. Use it for that endpoint — `popularTags` is the top-N
361
+ * leaderboard and its default of 20 silently drops every tag past the
362
+ * twentieth.
363
+ *
364
+ * @returns Every tag in use, with its article count.
365
+ */
366
+ export async function allTags() {
367
+ return countTagRows();
368
+ }
369
+ /**
370
+ * The `limit` most-used tags, most-used first (ties alphabetical).
371
+ *
372
+ * **This is a leaderboard, not "every tag".** The default is the top 20, so a
373
+ * `GET /tags`-shaped endpoint that returns all tags in use (RealWorld's
374
+ * `GET /api/tags`) must call `allTags` — or pass
375
+ * `Number.POSITIVE_INFINITY` — or it silently drops every tag past the
376
+ * twentieth once the database holds more than 20. Pass an explicit `limit`
377
+ * when the caller really did ask for the N most-used, e.g. a sidebar of ten.
378
+ *
379
+ * @param limit - How many tags to return, most-used first (default 20; `Number.POSITIVE_INFINITY` for every tag).
380
+ * @returns The tags with their article counts.
360
381
  */
361
382
  export async function popularTags(limit = 20) {
383
+ return (await countTagRows()).slice(0, Math.max(1, limit));
384
+ }
385
+ /**
386
+ * Tags in use with their article counts, most-used first (ties alphabetical).
387
+ *
388
+ * @returns Every tag in use.
389
+ */
390
+ const countTagRows = async () => {
362
391
  const rows = await findMany(ARTICLE_TAGS, {
363
392
  orderBy: TAGS_IN_ARTICLE_ORDER,
364
393
  select: ['tag'],
@@ -369,6 +398,5 @@ export async function popularTags(limit = 20) {
369
398
  counts.set(r.tag, (counts.get(r.tag) ?? 0) + 1);
370
399
  return [...counts.entries()]
371
400
  .sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
372
- .slice(0, Math.max(1, limit))
373
401
  .map(([tag, n]) => ({ tag, count: n }));
374
- }
402
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/api-resource-article",
3
- "version": "1.0.6",
3
+ "version": "1.1.0",
4
4
  "description": "Articles and blog posts: unique slugs, tags, favorites, a followed-authors feed, and filtered, paginated lists",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -34,7 +34,7 @@
34
34
  "license": "Apache-2.0",
35
35
  "devDependencies": {
36
36
  "@molecule/api-database": "1.1.3",
37
- "@molecule/api-database-sqlite": "1.2.4",
37
+ "@molecule/api-database-sqlite": "1.2.5",
38
38
  "@molecule/api-resource-follow": "1.0.7",
39
39
  "@molecule/api-resource-reaction": "1.0.4",
40
40
  "@molecule/api-slug": "1.0.1",