@molecule/api-resource-article 1.2.7 → 1.3.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.
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-11-15T03:10:10.469Z
6
+ Generated: 2026-11-19T03:20:24.668Z
7
7
  -->
8
8
 
9
9
  # @molecule/api-resource-article
@@ -22,7 +22,7 @@ favorites and follows the rest of the app sees.
22
22
  unique, and `article_tags.position` is the order the tags were given in). It also ships
23
23
  `src/__setup__/reactions.sql` and `src/__setup__/follows.sql`, which create the `reactions` and `follows` tables it reads by name.
24
24
 
25
- **HTTP format is configuration.** In the scaffold's `App/Resource/Article/index.ts`,
25
+ **Reuse the article tables for custom routes.** In the scaffold's `App/Resource/Article/index.ts`,
26
26
  export `requestHandlerMap = createArticleHandlers({ mapRequest, mapResponse })`.
27
27
  Keep `create`, `list`, `feed`, `read`, `update`, `del`, `favorite`, `unfavorite`
28
28
  and `tags` in the package.
@@ -37,7 +37,11 @@ Join those maps while projecting the page. This keeps the page at two relationsh
37
37
  queries even when many entries share an author; per-entry lookups repeat the same work.
38
38
 
39
39
  ```typescript
40
- import { createArticleHandlers } from '@molecule/api-resource-article'
40
+ import {
41
+ createArticleHandlers,
42
+ listArticles,
43
+ type ListArticlesOptions,
44
+ } from '@molecule/api-resource-article'
41
45
 
42
46
  export const requestHandlerMap = createArticleHandlers({
43
47
  mapRequest: (req) => ({ body: req.body?.entry }),
@@ -46,18 +50,38 @@ export const requestHandlerMap = createArticleHandlers({
46
50
  ? result
47
51
  : { ...result, body: { entry: result.body } },
48
52
  })
53
+
54
+ // For a custom list route, resolve public handles to user ids in the app.
55
+ // Pass those ids as authorId and favoritedBy, and the current reader as viewerId.
56
+ export async function listEntryPreviews(filters: ListArticlesOptions) {
57
+ const { data, total } = await listArticles(filters)
58
+ return {
59
+ entries: data.map(({ id, slug, title, favorited }) => ({ id, slug, title, favorited })),
60
+ entriesCount: total,
61
+ }
62
+ }
49
63
  ```
50
64
 
51
65
  Use the resulting map's handlers on the app's routes. For distinct route projections,
52
66
  create separate maps with separate options. The static `requestHandlerMap` keeps the
53
- native flat-body/raw-article format. Use service functions for a different domain workflow.
54
- Read Quick Start for filter mapping and early responses.
67
+ native flat-body/raw-article format. A list can combine tag, author and favorites
68
+ filters with limit and offset. When a requested handle cannot be resolved, return an
69
+ empty page instead of omitting its filter. `getFeed(viewerId, { limit, offset })`
70
+ handles the followed-author view. The services read the package's tables, so a
71
+ differently named table with its own schema needs its own persistence.
55
72
 
56
73
  **Need only a lookup in a custom route?** `findArticleRow(slug)` returns the stored
57
74
  `ArticleRow` or `null`. `getArticleBySlug(slug, viewerId?)` returns an `Article` or
58
75
  `null`, with ordered tags, favorite count and the viewer's `favorited` state.
59
76
  Both read this package's `articles` table. Keep your route, author-profile lookup
60
77
  and response projection local; call these functions instead of copying the slug query.
78
+ `uniqueArticleSlug(title, excludeId?)` exposes the same free-slug policy used by
79
+ `createArticle` and `updateArticle`, including reserved route words and the
80
+ `article` fallback. Use it for a custom workflow that needs a slug before writing;
81
+ use `createArticle` for a normal create. It checks availability without reserving
82
+ a slug, so retain the UNIQUE index and retry a conflicting insert. A different
83
+ table can use `uniqueSlugInTable(table, column, title, { excludeId })` from
84
+ `@molecule/api-slug`; its general policy does not reserve this resource's routes.
61
85
 
62
86
  ```typescript
63
87
  import { findArticleRow } from '@molecule/api-resource-article'
@@ -322,6 +346,23 @@ function createArticleHandlers(options?: RequestHandlerOptions): ArticleRequestH
322
346
 
323
347
  **Returns:** A route-compatible map with the same names as requestHandlerMap.
324
348
 
349
+ #### `uniqueArticleSlug(title, excludeId)`
350
+
351
+ Find a free slug in this package's articles table without writing an article.
352
+ Uses the same normalization, reserved route slugs and fallback as createArticle
353
+ and updateArticle. This is a lookup, not a reservation: keep the table's UNIQUE
354
+ index and retry a conflicting insert. For another table use api-slug's
355
+ uniqueSlugInTable instead.
356
+
357
+ ```typescript
358
+ function uniqueArticleSlug(title: string, excludeId?: string): Promise<string>
359
+ ```
360
+
361
+ - `title` — The article title.
362
+ - `excludeId` — The existing article's id, so it may keep its own slug on update.
363
+
364
+ **Returns:** An unused article slug; empty normalized titles use `article`.
365
+
325
366
  #### `hydrateArticles(rows, viewerId)`
326
367
 
327
368
  Turn stored rows into {@link Article}s: decoded tags, favorite counts and the
package/dist/index.d.ts CHANGED
@@ -13,7 +13,7 @@
13
13
  * unique, and `article_tags.position` is the order the tags were given in). It also ships
14
14
  * `src/__setup__/reactions.sql` and `src/__setup__/follows.sql`, which create the `reactions` and `follows` tables it reads by name.
15
15
  *
16
- * **HTTP format is configuration.** In the scaffold's `App/Resource/Article/index.ts`,
16
+ * **Reuse the article tables for custom routes.** In the scaffold's `App/Resource/Article/index.ts`,
17
17
  * export `requestHandlerMap = createArticleHandlers({ mapRequest, mapResponse })`.
18
18
  * Keep `create`, `list`, `feed`, `read`, `update`, `del`, `favorite`, `unfavorite`
19
19
  * and `tags` in the package.
@@ -28,7 +28,7 @@
28
28
  * queries even when many entries share an author; per-entry lookups repeat the same work.
29
29
  *
30
30
  * ```typescript
31
- * import { createArticleHandlers } from '@molecule/api-resource-article'
31
+ * import { createArticleHandlers, listArticles, type ListArticlesOptions } from '@molecule/api-resource-article'
32
32
  *
33
33
  * export const requestHandlerMap = createArticleHandlers({
34
34
  * mapRequest: (req) => ({ body: req.body?.entry }),
@@ -36,18 +36,38 @@
36
36
  * ? result
37
37
  * : { ...result, body: { entry: result.body } },
38
38
  * })
39
+ *
40
+ * // For a custom list route, resolve public handles to user ids in the app.
41
+ * // Pass those ids as authorId and favoritedBy, and the current reader as viewerId.
42
+ * export async function listEntryPreviews(filters: ListArticlesOptions) {
43
+ * const { data, total } = await listArticles(filters)
44
+ * return {
45
+ * entries: data.map(({ id, slug, title, favorited }) => ({ id, slug, title, favorited })),
46
+ * entriesCount: total,
47
+ * }
48
+ * }
39
49
  * ```
40
50
  *
41
51
  * Use the resulting map's handlers on the app's routes. For distinct route projections,
42
52
  * create separate maps with separate options. The static `requestHandlerMap` keeps the
43
- * native flat-body/raw-article format. Use service functions for a different domain workflow.
44
- * Read Quick Start for filter mapping and early responses.
53
+ * native flat-body/raw-article format. A list can combine tag, author and favorites
54
+ * filters with limit and offset. When a requested handle cannot be resolved, return an
55
+ * empty page instead of omitting its filter. `getFeed(viewerId, { limit, offset })`
56
+ * handles the followed-author view. The services read the package's tables, so a
57
+ * differently named table with its own schema needs its own persistence.
45
58
  *
46
59
  * **Need only a lookup in a custom route?** `findArticleRow(slug)` returns the stored
47
60
  * `ArticleRow` or `null`. `getArticleBySlug(slug, viewerId?)` returns an `Article` or
48
61
  * `null`, with ordered tags, favorite count and the viewer's `favorited` state.
49
62
  * Both read this package's `articles` table. Keep your route, author-profile lookup
50
63
  * and response projection local; call these functions instead of copying the slug query.
64
+ * `uniqueArticleSlug(title, excludeId?)` exposes the same free-slug policy used by
65
+ * `createArticle` and `updateArticle`, including reserved route words and the
66
+ * `article` fallback. Use it for a custom workflow that needs a slug before writing;
67
+ * use `createArticle` for a normal create. It checks availability without reserving
68
+ * a slug, so retain the UNIQUE index and retry a conflicting insert. A different
69
+ * table can use `uniqueSlugInTable(table, column, title, { excludeId })` from
70
+ * `@molecule/api-slug`; its general policy does not reserve this resource's routes.
51
71
  *
52
72
  * ```typescript
53
73
  * import { findArticleRow } from '@molecule/api-resource-article'
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+KG;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmMG;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
@@ -13,7 +13,7 @@
13
13
  * unique, and `article_tags.position` is the order the tags were given in). It also ships
14
14
  * `src/__setup__/reactions.sql` and `src/__setup__/follows.sql`, which create the `reactions` and `follows` tables it reads by name.
15
15
  *
16
- * **HTTP format is configuration.** In the scaffold's `App/Resource/Article/index.ts`,
16
+ * **Reuse the article tables for custom routes.** In the scaffold's `App/Resource/Article/index.ts`,
17
17
  * export `requestHandlerMap = createArticleHandlers({ mapRequest, mapResponse })`.
18
18
  * Keep `create`, `list`, `feed`, `read`, `update`, `del`, `favorite`, `unfavorite`
19
19
  * and `tags` in the package.
@@ -28,7 +28,7 @@
28
28
  * queries even when many entries share an author; per-entry lookups repeat the same work.
29
29
  *
30
30
  * ```typescript
31
- * import { createArticleHandlers } from '@molecule/api-resource-article'
31
+ * import { createArticleHandlers, listArticles, type ListArticlesOptions } from '@molecule/api-resource-article'
32
32
  *
33
33
  * export const requestHandlerMap = createArticleHandlers({
34
34
  * mapRequest: (req) => ({ body: req.body?.entry }),
@@ -36,18 +36,38 @@
36
36
  * ? result
37
37
  * : { ...result, body: { entry: result.body } },
38
38
  * })
39
+ *
40
+ * // For a custom list route, resolve public handles to user ids in the app.
41
+ * // Pass those ids as authorId and favoritedBy, and the current reader as viewerId.
42
+ * export async function listEntryPreviews(filters: ListArticlesOptions) {
43
+ * const { data, total } = await listArticles(filters)
44
+ * return {
45
+ * entries: data.map(({ id, slug, title, favorited }) => ({ id, slug, title, favorited })),
46
+ * entriesCount: total,
47
+ * }
48
+ * }
39
49
  * ```
40
50
  *
41
51
  * Use the resulting map's handlers on the app's routes. For distinct route projections,
42
52
  * create separate maps with separate options. The static `requestHandlerMap` keeps the
43
- * native flat-body/raw-article format. Use service functions for a different domain workflow.
44
- * Read Quick Start for filter mapping and early responses.
53
+ * native flat-body/raw-article format. A list can combine tag, author and favorites
54
+ * filters with limit and offset. When a requested handle cannot be resolved, return an
55
+ * empty page instead of omitting its filter. `getFeed(viewerId, { limit, offset })`
56
+ * handles the followed-author view. The services read the package's tables, so a
57
+ * differently named table with its own schema needs its own persistence.
45
58
  *
46
59
  * **Need only a lookup in a custom route?** `findArticleRow(slug)` returns the stored
47
60
  * `ArticleRow` or `null`. `getArticleBySlug(slug, viewerId?)` returns an `Article` or
48
61
  * `null`, with ordered tags, favorite count and the viewer's `favorited` state.
49
62
  * Both read this package's `articles` table. Keep your route, author-profile lookup
50
63
  * and response projection local; call these functions instead of copying the slug query.
64
+ * `uniqueArticleSlug(title, excludeId?)` exposes the same free-slug policy used by
65
+ * `createArticle` and `updateArticle`, including reserved route words and the
66
+ * `article` fallback. Use it for a custom workflow that needs a slug before writing;
67
+ * use `createArticle` for a normal create. It checks availability without reserving
68
+ * a slug, so retain the UNIQUE index and retry a conflicting insert. A different
69
+ * table can use `uniqueSlugInTable(table, column, title, { excludeId })` from
70
+ * `@molecule/api-slug`; its general policy does not reserve this resource's routes.
51
71
  *
52
72
  * ```typescript
53
73
  * import { findArticleRow } from '@molecule/api-resource-article'
package/dist/service.d.ts CHANGED
@@ -20,6 +20,18 @@ export declare const FAVORITE_REACTION = "favorite";
20
20
  * article titled "Feed" gets `feed-2`, or its page would be unreachable.
21
21
  */
22
22
  export declare const RESERVED_ARTICLE_SLUGS: ReadonlySet<string>;
23
+ /**
24
+ * Find a free slug in this package's articles table without writing an article.
25
+ * Uses the same normalization, reserved route slugs and fallback as createArticle
26
+ * and updateArticle. This is a lookup, not a reservation: keep the table's UNIQUE
27
+ * index and retry a conflicting insert. For another table use api-slug's
28
+ * uniqueSlugInTable instead.
29
+ *
30
+ * @param title - The article title.
31
+ * @param excludeId - The existing article's id, so it may keep its own slug on update.
32
+ * @returns An unused article slug; empty normalized titles use `article`.
33
+ */
34
+ export declare function uniqueArticleSlug(title: string, excludeId?: string): Promise<string>;
23
35
  /** Largest page a list returns. */
24
36
  export declare const MAX_ARTICLES_PAGE = 100;
25
37
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAeH,OAAO,KAAK,EACV,OAAO,EACP,UAAU,EACV,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,QAAQ,EACR,kBAAkB,EACnB,MAAM,YAAY,CAAA;AAOnB,6EAA6E;AAC7E,eAAO,MAAM,qBAAqB,YAAY,CAAA;AAE9C,iDAAiD;AACjD,eAAO,MAAM,iBAAiB,aAAa,CAAA;AAE3C;;;GAGG;AACH,eAAO,MAAM,sBAAsB,EAAE,WAAW,CAAC,MAAM,CAA6B,CAAA;AA0CpF,mCAAmC;AACnC,eAAO,MAAM,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AE,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
@@ -26,15 +26,27 @@ export const FAVORITE_REACTION = 'favorite';
26
26
  * article titled "Feed" gets `feed-2`, or its page would be unreachable.
27
27
  */
28
28
  export const RESERVED_ARTICLE_SLUGS = new Set(['feed', 'tags']);
29
- /** A free slug for a title; `excludeId` lets an article keep its own on update. */
30
- const articleSlug = (title, excludeId) => uniqueSlug(title, async (slug) => {
31
- if (RESERVED_ARTICLE_SLUGS.has(slug))
32
- return true;
33
- const row = await findOne(ARTICLES, [
34
- { field: 'slug', operator: '=', value: slug },
35
- ]);
36
- return row != null && row.id !== excludeId;
37
- }, { fallback: 'article' });
29
+ /**
30
+ * Find a free slug in this package's articles table without writing an article.
31
+ * Uses the same normalization, reserved route slugs and fallback as createArticle
32
+ * and updateArticle. This is a lookup, not a reservation: keep the table's UNIQUE
33
+ * index and retry a conflicting insert. For another table use api-slug's
34
+ * uniqueSlugInTable instead.
35
+ *
36
+ * @param title - The article title.
37
+ * @param excludeId - The existing article's id, so it may keep its own slug on update.
38
+ * @returns An unused article slug; empty normalized titles use `article`.
39
+ */
40
+ export function uniqueArticleSlug(title, excludeId) {
41
+ return uniqueSlug(title, async (slug) => {
42
+ if (RESERVED_ARTICLE_SLUGS.has(slug))
43
+ return true;
44
+ const row = await findOne(ARTICLES, [
45
+ { field: 'slug', operator: '=', value: slug },
46
+ ]);
47
+ return row != null && row.id !== excludeId;
48
+ }, { fallback: 'article' });
49
+ }
38
50
  let lastCreatedMs = 0;
39
51
  /**
40
52
  * A creation time later than every earlier one from this process: two
@@ -148,7 +160,7 @@ const writeTags = async (articleId, tags) => {
148
160
  * @returns The created article.
149
161
  */
150
162
  export async function createArticle(authorId, input) {
151
- const slug = await articleSlug(input.title);
163
+ const slug = await uniqueArticleSlug(input.title);
152
164
  const tags = cleanTags(input.tagList);
153
165
  // Written here rather than left to the column default: the default is
154
166
  // millisecond-precision, so two articles created inside the same millisecond
@@ -312,7 +324,7 @@ export async function updateArticle(slug, userId, input) {
312
324
  const patch = { updatedAt: nextUpdatedAt(row.updatedAt) };
313
325
  if (input.title !== undefined && input.title !== row.title) {
314
326
  patch.title = input.title;
315
- patch.slug = await articleSlug(input.title, row.id);
327
+ patch.slug = await uniqueArticleSlug(input.title, row.id);
316
328
  }
317
329
  if (input.description !== undefined)
318
330
  patch.description = input.description;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/api-resource-article",
3
- "version": "1.2.7",
3
+ "version": "1.3.1",
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",
@@ -35,9 +35,9 @@
35
35
  "devDependencies": {
36
36
  "@molecule/api-database": "1.2.2",
37
37
  "@molecule/api-database-sqlite": "1.4.3",
38
- "@molecule/api-resource-follow": "1.1.1",
38
+ "@molecule/api-resource-follow": "1.1.3",
39
39
  "@molecule/api-resource-reaction": "1.0.8",
40
- "@molecule/api-slug": "1.0.3",
40
+ "@molecule/api-slug": "1.0.4",
41
41
  "@types/express": "5.0.6",
42
42
  "@types/node": "26.6.5",
43
43
  "express": "5.3.0",