tibber-express-utils 4.0.21 → 4.0.22
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/dist/src/types.d.ts +8 -4
- package/package.json +2 -1
- package/readme.md +29 -0
package/dist/src/types.d.ts
CHANGED
|
@@ -23,8 +23,6 @@ export type ContextSelector<TContext> = (request: Request) => TContext;
|
|
|
23
23
|
/**
|
|
24
24
|
* A JsonRouter is an express.Router instance that also provides shorthand HTTP methods
|
|
25
25
|
* using Tibber's jsonMiddleware under the 'jsonXXX' naming convention.
|
|
26
|
-
*
|
|
27
|
-
* Poke changing for feat.
|
|
28
26
|
*/
|
|
29
27
|
export type JsonRouter<TContext> = Router & {
|
|
30
28
|
jsonDelete: JsonRouteMatcher<TContext>;
|
|
@@ -46,13 +44,19 @@ export type JsonRouteMatcher<TContext> = {
|
|
|
46
44
|
* the Request object and (optionally) a Context instance that has been
|
|
47
45
|
* extracted from the Request by the JsonRouter.
|
|
48
46
|
*
|
|
49
|
-
* It is expected that the handler returns a JsonRequestHandlerResult
|
|
47
|
+
* It is expected that the handler returns a JsonRequestHandlerResult, either
|
|
48
|
+
* directly or as a Promise — jsonMiddleware awaits the return value, so an
|
|
49
|
+
* `async` handler (the common case for anything doing I/O) is supported.
|
|
50
50
|
*/
|
|
51
|
-
export type JsonRequestHandler<TContext, TPayload> = (req: Request, ctx: TContext) => JsonRequestHandlerResult<TPayload
|
|
51
|
+
export type JsonRequestHandler<TContext, TPayload> = (req: Request, ctx: TContext) => JsonRequestHandlerResult<TPayload> | Promise<JsonRequestHandlerResult<TPayload>>;
|
|
52
52
|
/**
|
|
53
53
|
* The allowable return types of a JsonRequestHandler. A JsonRequestHandler
|
|
54
54
|
* may return undefined, an HTTP status code (number) or an HttpResult
|
|
55
55
|
* encapsulating a TPayload instance.
|
|
56
|
+
*
|
|
57
|
+
* This is the *awaited* result: a handler may also return a Promise of it
|
|
58
|
+
* (see JsonRequestHandler). Guards such as isHttpResult operate on the
|
|
59
|
+
* resolved value, so they keep taking this synchronous shape.
|
|
56
60
|
*/
|
|
57
61
|
export type JsonRequestHandlerResult<TPayload> = undefined | HttpResult<TPayload> | TPayload | number;
|
|
58
62
|
/**
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tibber-express-utils",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.22",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/src/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "jest --verbose",
|
|
8
|
+
"test:consumer": "bash test/consumer/run.sh",
|
|
8
9
|
"test-single": "jest --verbose jsonDelete.spec.ts",
|
|
9
10
|
"lint": "gts lint",
|
|
10
11
|
"clean": "gts clean",
|
package/readme.md
CHANGED
|
@@ -25,6 +25,35 @@ from npm, the next merge of any kind publishes it. (Versions 4.0.14–4.0.18 wer
|
|
|
25
25
|
tagged during the broken-token era but never reached npm; consumers jump
|
|
26
26
|
from 4.0.13 straight to the first post-fix release.)
|
|
27
27
|
|
|
28
|
+
## Tests
|
|
29
|
+
|
|
30
|
+
| Command | What it covers |
|
|
31
|
+
|---|---|
|
|
32
|
+
| `yarn test` | Unit suite (jest). Imports from `src/`, so it verifies behaviour but **not** the published package. |
|
|
33
|
+
| `yarn test:consumer` | Consumer smoke test. Packs the library and installs the tarball into a scratch project outside the repo, then verifies it as a consumer sees it. |
|
|
34
|
+
|
|
35
|
+
`yarn test:consumer` ([test/consumer/](test/consumer/)) exists because the unit
|
|
36
|
+
suite cannot fail for a whole class of breakage: a bad `main` or `files` entry, a
|
|
37
|
+
renamed or dropped export, or `.d.ts` files a consumer can't resolve all leave it
|
|
38
|
+
green while shipping a broken package. It asserts:
|
|
39
|
+
|
|
40
|
+
- the package loads via plain `require`, and its export surface matches the
|
|
41
|
+
committed snapshot in `test/consumer/expected-exports.json` — changing that
|
|
42
|
+
file is how an API addition or removal becomes a reviewable decision;
|
|
43
|
+
- a real Express app wired through the **installed** `jsonRouting` serves
|
|
44
|
+
requests, including the per-verb default status selectors (`jsonGet` →
|
|
45
|
+
`undefined` = 404; `jsonDelete` → `undefined` = 204, truthy = 202), thrown
|
|
46
|
+
`HttpError` mapping, that a supplied `Logger` receives handler errors, and that
|
|
47
|
+
errors still propagate via `next(err)` after the response is sent;
|
|
48
|
+
- the emitted declarations type-check under `tsc --strict` from a consumer's own
|
|
49
|
+
tsconfig. Note `package.json` declares no `types` field, so type resolution
|
|
50
|
+
relies on tsc's `main` → `<main>.d.ts` fallback — this probe is what keeps that
|
|
51
|
+
working.
|
|
52
|
+
|
|
53
|
+
It runs against both ends of the Express peer range (the `5.0.0` floor and the
|
|
54
|
+
newest `^5`), and CI runs it **before** `yarn release`, so none of the above can
|
|
55
|
+
publish.
|
|
56
|
+
|
|
28
57
|
## Requirements
|
|
29
58
|
|
|
30
59
|
- **Node.js**: 18 or higher
|