@molecule/api-resource-article 1.2.0 → 1.2.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 +41 -1
- package/dist/index.d.ts +39 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -0
- package/package.json +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-11-
|
|
6
|
+
Generated: 2026-11-10T00:54:38.649Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/api-resource-article
|
|
@@ -22,6 +22,46 @@ 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`,
|
|
26
|
+
export `requestHandlerMap = createArticleHandlers({ mapRequest, mapResponse })`.
|
|
27
|
+
Keep `create`, `list`, `feed`, `read`, `update`, `del`, `favorite`, `unfavorite`
|
|
28
|
+
and `tags` in the package.
|
|
29
|
+
`mapRequest` can unwrap bodies and resolve query filters. Async `mapResponse`
|
|
30
|
+
can batch-load author profiles, omit fields from list items, rename pagination
|
|
31
|
+
keys, wrap results, or translate error statuses and bodies. It receives errors
|
|
32
|
+
and empty deletes too. Set the authenticated user on `res.locals.session.userId`.
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { createArticleHandlers } from '@molecule/api-resource-article'
|
|
36
|
+
|
|
37
|
+
export const requestHandlerMap = createArticleHandlers({
|
|
38
|
+
mapRequest: (req) => ({ body: req.body?.entry }),
|
|
39
|
+
mapResponse: (result) =>
|
|
40
|
+
result.statusCode >= 400 || result.statusCode === 204
|
|
41
|
+
? result
|
|
42
|
+
: { ...result, body: { entry: result.body } },
|
|
43
|
+
})
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Use the resulting map's handlers on the app's routes. For distinct route projections,
|
|
47
|
+
create separate maps with separate options. The static `requestHandlerMap` keeps the
|
|
48
|
+
native flat-body/raw-article format. Use service functions for a different domain workflow.
|
|
49
|
+
Read Quick Start for filter mapping and early responses.
|
|
50
|
+
|
|
51
|
+
**Need only a lookup in a custom route?** `findArticleRow(slug)` returns the stored
|
|
52
|
+
`ArticleRow` or `null`. `getArticleBySlug(slug, viewerId?)` returns an `Article` or
|
|
53
|
+
`null`, with ordered tags, favorite count and the viewer's `favorited` state.
|
|
54
|
+
Both read this package's `articles` table. Keep your route, author-profile lookup
|
|
55
|
+
and response projection local; call these functions instead of copying the slug query.
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { findArticleRow } from '@molecule/api-resource-article'
|
|
59
|
+
|
|
60
|
+
const slug = 'release-notes'
|
|
61
|
+
const row = await findArticleRow(slug)
|
|
62
|
+
// Map row (or null) into this API's response. Use getArticleBySlug for hydrated fields.
|
|
63
|
+
```
|
|
64
|
+
|
|
25
65
|
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
26
66
|
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
27
67
|
> package's source — edit `src/index.ts` JSDoc, not this file.
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,45 @@
|
|
|
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`,
|
|
17
|
+
* export `requestHandlerMap = createArticleHandlers({ mapRequest, mapResponse })`.
|
|
18
|
+
* Keep `create`, `list`, `feed`, `read`, `update`, `del`, `favorite`, `unfavorite`
|
|
19
|
+
* and `tags` in the package.
|
|
20
|
+
* `mapRequest` can unwrap bodies and resolve query filters. Async `mapResponse`
|
|
21
|
+
* can batch-load author profiles, omit fields from list items, rename pagination
|
|
22
|
+
* keys, wrap results, or translate error statuses and bodies. It receives errors
|
|
23
|
+
* and empty deletes too. Set the authenticated user on `res.locals.session.userId`.
|
|
24
|
+
*
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import { createArticleHandlers } from '@molecule/api-resource-article'
|
|
27
|
+
*
|
|
28
|
+
* export const requestHandlerMap = createArticleHandlers({
|
|
29
|
+
* mapRequest: (req) => ({ body: req.body?.entry }),
|
|
30
|
+
* mapResponse: (result) => result.statusCode >= 400 || result.statusCode === 204
|
|
31
|
+
* ? result
|
|
32
|
+
* : { ...result, body: { entry: result.body } },
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* Use the resulting map's handlers on the app's routes. For distinct route projections,
|
|
37
|
+
* create separate maps with separate options. The static `requestHandlerMap` keeps the
|
|
38
|
+
* native flat-body/raw-article format. Use service functions for a different domain workflow.
|
|
39
|
+
* Read Quick Start for filter mapping and early responses.
|
|
40
|
+
*
|
|
41
|
+
* **Need only a lookup in a custom route?** `findArticleRow(slug)` returns the stored
|
|
42
|
+
* `ArticleRow` or `null`. `getArticleBySlug(slug, viewerId?)` returns an `Article` or
|
|
43
|
+
* `null`, with ordered tags, favorite count and the viewer's `favorited` state.
|
|
44
|
+
* Both read this package's `articles` table. Keep your route, author-profile lookup
|
|
45
|
+
* and response projection local; call these functions instead of copying the slug query.
|
|
46
|
+
*
|
|
47
|
+
* ```typescript
|
|
48
|
+
* import { findArticleRow } from '@molecule/api-resource-article'
|
|
49
|
+
*
|
|
50
|
+
* const slug = 'release-notes'
|
|
51
|
+
* const row = await findArticleRow(slug)
|
|
52
|
+
* // Map row (or null) into this API's response. Use getArticleBySlug for hydrated fields.
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
16
55
|
* @module
|
|
17
56
|
* @example
|
|
18
57
|
* ```typescript
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuKG;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,6 +13,45 @@
|
|
|
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`,
|
|
17
|
+
* export `requestHandlerMap = createArticleHandlers({ mapRequest, mapResponse })`.
|
|
18
|
+
* Keep `create`, `list`, `feed`, `read`, `update`, `del`, `favorite`, `unfavorite`
|
|
19
|
+
* and `tags` in the package.
|
|
20
|
+
* `mapRequest` can unwrap bodies and resolve query filters. Async `mapResponse`
|
|
21
|
+
* can batch-load author profiles, omit fields from list items, rename pagination
|
|
22
|
+
* keys, wrap results, or translate error statuses and bodies. It receives errors
|
|
23
|
+
* and empty deletes too. Set the authenticated user on `res.locals.session.userId`.
|
|
24
|
+
*
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import { createArticleHandlers } from '@molecule/api-resource-article'
|
|
27
|
+
*
|
|
28
|
+
* export const requestHandlerMap = createArticleHandlers({
|
|
29
|
+
* mapRequest: (req) => ({ body: req.body?.entry }),
|
|
30
|
+
* mapResponse: (result) => result.statusCode >= 400 || result.statusCode === 204
|
|
31
|
+
* ? result
|
|
32
|
+
* : { ...result, body: { entry: result.body } },
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* Use the resulting map's handlers on the app's routes. For distinct route projections,
|
|
37
|
+
* create separate maps with separate options. The static `requestHandlerMap` keeps the
|
|
38
|
+
* native flat-body/raw-article format. Use service functions for a different domain workflow.
|
|
39
|
+
* Read Quick Start for filter mapping and early responses.
|
|
40
|
+
*
|
|
41
|
+
* **Need only a lookup in a custom route?** `findArticleRow(slug)` returns the stored
|
|
42
|
+
* `ArticleRow` or `null`. `getArticleBySlug(slug, viewerId?)` returns an `Article` or
|
|
43
|
+
* `null`, with ordered tags, favorite count and the viewer's `favorited` state.
|
|
44
|
+
* Both read this package's `articles` table. Keep your route, author-profile lookup
|
|
45
|
+
* and response projection local; call these functions instead of copying the slug query.
|
|
46
|
+
*
|
|
47
|
+
* ```typescript
|
|
48
|
+
* import { findArticleRow } from '@molecule/api-resource-article'
|
|
49
|
+
*
|
|
50
|
+
* const slug = 'release-notes'
|
|
51
|
+
* const row = await findArticleRow(slug)
|
|
52
|
+
* // Map row (or null) into this API's response. Use getArticleBySlug for hydrated fields.
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
16
55
|
* @module
|
|
17
56
|
* @example
|
|
18
57
|
* ```typescript
|
package/package.json
CHANGED