@molecule/api-resource 1.0.3 → 1.0.4
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 +17 -1
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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-
|
|
6
|
+
Generated: 2026-10-16T20:59:23.498Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/api-resource
|
|
@@ -18,6 +18,22 @@ Provides CRUD operation factories and request handler utilities for
|
|
|
18
18
|
building RESTful API resources. Every `@molecule/api-resource-*` package
|
|
19
19
|
(user, project, device, ...) is built on these factories.
|
|
20
20
|
|
|
21
|
+
**A handler returns `{ statusCode, headers?, body }` and NEVER writes to `res`** — not through
|
|
22
|
+
`res.json`, not through `res.send`, not through `res.end`. `createRequestHandler` is the wrapper
|
|
23
|
+
that applies the returned object (`res.set(headers)`, `res.status(statusCode)`, `res.send(body)`),
|
|
24
|
+
and a handler returns `null` only when the request should fall through to `next()`. Calling a
|
|
25
|
+
handler directly from your own route is therefore only correct if you apply that return value
|
|
26
|
+
yourself:
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
const { statusCode, headers, body } = await handler(req, res)
|
|
30
|
+
if (headers) res.set(headers)
|
|
31
|
+
res.status(statusCode).send(body)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Monkey-patching `res.json` (or `res.send`/`res.end`) to re-shape a handler's answer intercepts
|
|
35
|
+
nothing the handler produces, so the request it was meant to answer is left unanswered and hangs.
|
|
36
|
+
|
|
21
37
|
## Quick Start
|
|
22
38
|
|
|
23
39
|
```typescript
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,22 @@
|
|
|
5
5
|
* building RESTful API resources. Every `@molecule/api-resource-*` package
|
|
6
6
|
* (user, project, device, ...) is built on these factories.
|
|
7
7
|
*
|
|
8
|
+
* **A handler returns `{ statusCode, headers?, body }` and NEVER writes to `res`** — not through
|
|
9
|
+
* `res.json`, not through `res.send`, not through `res.end`. `createRequestHandler` is the wrapper
|
|
10
|
+
* that applies the returned object (`res.set(headers)`, `res.status(statusCode)`, `res.send(body)`),
|
|
11
|
+
* and a handler returns `null` only when the request should fall through to `next()`. Calling a
|
|
12
|
+
* handler directly from your own route is therefore only correct if you apply that return value
|
|
13
|
+
* yourself:
|
|
14
|
+
*
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const { statusCode, headers, body } = await handler(req, res)
|
|
17
|
+
* if (headers) res.set(headers)
|
|
18
|
+
* res.status(statusCode).send(body)
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Monkey-patching `res.json` (or `res.send`/`res.end`) to re-shape a handler's answer intercepts
|
|
22
|
+
* nothing the handler produces, so the request it was meant to answer is left unanswered and hangs.
|
|
23
|
+
*
|
|
8
24
|
* @example
|
|
9
25
|
* ```typescript
|
|
10
26
|
* import { z } from 'zod'
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqGG;AAEH,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,2BAA2B,CAAA;AACzC,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,oBAAoB,CAAA;AAClC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,cAAc,aAAa,CAAA;AAC3B,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,22 @@
|
|
|
5
5
|
* building RESTful API resources. Every `@molecule/api-resource-*` package
|
|
6
6
|
* (user, project, device, ...) is built on these factories.
|
|
7
7
|
*
|
|
8
|
+
* **A handler returns `{ statusCode, headers?, body }` and NEVER writes to `res`** — not through
|
|
9
|
+
* `res.json`, not through `res.send`, not through `res.end`. `createRequestHandler` is the wrapper
|
|
10
|
+
* that applies the returned object (`res.set(headers)`, `res.status(statusCode)`, `res.send(body)`),
|
|
11
|
+
* and a handler returns `null` only when the request should fall through to `next()`. Calling a
|
|
12
|
+
* handler directly from your own route is therefore only correct if you apply that return value
|
|
13
|
+
* yourself:
|
|
14
|
+
*
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const { statusCode, headers, body } = await handler(req, res)
|
|
17
|
+
* if (headers) res.set(headers)
|
|
18
|
+
* res.status(statusCode).send(body)
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Monkey-patching `res.json` (or `res.send`/`res.end`) to re-shape a handler's answer intercepts
|
|
22
|
+
* nothing the handler produces, so the request it was meant to answer is left unanswered and hangs.
|
|
23
|
+
*
|
|
8
24
|
* @example
|
|
9
25
|
* ```typescript
|
|
10
26
|
* import { z } from 'zod'
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqGG;AAEH,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,2BAA2B,CAAA;AACzC,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,oBAAoB,CAAA;AAClC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,cAAc,aAAa,CAAA;AAC3B,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/api-resource",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Resource CRUD operations and utilities for molecule.dev.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@molecule/api-bond": "1.0.2",
|
|
43
|
-
"@molecule/api-database": "1.1.
|
|
43
|
+
"@molecule/api-database": "1.1.3",
|
|
44
44
|
"@molecule/api-locales-resource": "1.0.2",
|
|
45
45
|
"@molecule/api-utilities-validation": "1.0.2",
|
|
46
46
|
"@types/node": "26.1.2",
|