tibber-express-utils 3.5.0 → 4.0.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/dist/src/HttpResult.d.ts
CHANGED
package/dist/src/types.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { HttpResult } from './HttpResult';
|
|
|
4
4
|
/**
|
|
5
5
|
* Params for constructing the jsonRouter.
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export type JsonRouterParams<TContext = unknown> = {
|
|
8
8
|
contextSelector?: ContextSelector<TContext>;
|
|
9
9
|
expressRouter: Router;
|
|
10
10
|
logger?: Logger;
|
|
@@ -13,20 +13,20 @@ export declare type JsonRouterParams<TContext = unknown> = {
|
|
|
13
13
|
* Configures an express.Router instance as a JsonRouter, adding the 'jsonXXX'
|
|
14
14
|
* api which routes requests through Tibber's jsonMiddleware.
|
|
15
15
|
*/
|
|
16
|
-
export
|
|
16
|
+
export type JsonRouting<TContext = unknown> = {
|
|
17
17
|
(jsonRouterParams: JsonRouterParams<TContext>): JsonRouter<TContext>;
|
|
18
18
|
};
|
|
19
19
|
/**
|
|
20
20
|
* Where relevant, extracts a context object from the express Request instance.
|
|
21
21
|
*/
|
|
22
|
-
export
|
|
22
|
+
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
26
|
*
|
|
27
27
|
* Poke changing for feat.
|
|
28
28
|
*/
|
|
29
|
-
export
|
|
29
|
+
export type JsonRouter<TContext> = Router & {
|
|
30
30
|
jsonDelete: JsonRouteMatcher<TContext>;
|
|
31
31
|
jsonGet: JsonRouteMatcher<TContext>;
|
|
32
32
|
jsonPatch: JsonRouteMatcher<TContext>;
|
|
@@ -36,7 +36,7 @@ export declare type JsonRouter<TContext> = Router & {
|
|
|
36
36
|
/**
|
|
37
37
|
* Defines the JsonRequestHandler that is to be used for a specific path.
|
|
38
38
|
*/
|
|
39
|
-
export
|
|
39
|
+
export type JsonRouteMatcher<TContext> = {
|
|
40
40
|
<TPayload>(path: PathParams, handler: JsonRequestHandler<TContext, TPayload>): JsonRouter<TContext>;
|
|
41
41
|
};
|
|
42
42
|
/**
|
|
@@ -48,13 +48,13 @@ export declare type JsonRouteMatcher<TContext> = {
|
|
|
48
48
|
*
|
|
49
49
|
* It is expected that the handler returns a JsonRequestHandlerResult.
|
|
50
50
|
*/
|
|
51
|
-
export
|
|
51
|
+
export type JsonRequestHandler<TContext, TPayload> = (req: Request, ctx: TContext) => 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
56
|
*/
|
|
57
|
-
export
|
|
57
|
+
export type JsonRequestHandlerResult<TPayload> = undefined | HttpResult<TPayload> | TPayload | number;
|
|
58
58
|
/**
|
|
59
59
|
* The Logger interface whose implementation is to be supplied by the consuming service.
|
|
60
60
|
*/
|
|
@@ -77,11 +77,11 @@ export interface Logger {
|
|
|
77
77
|
* An Logger instance, if provided, will receive error messages raised during
|
|
78
78
|
* request handling.
|
|
79
79
|
*/
|
|
80
|
-
export
|
|
80
|
+
export type JsonMiddleware = {
|
|
81
81
|
<TContext, TPayload>(httpStatusCodeSelector: HttpStatusCodeSelector, contextSelector: ContextSelector<TContext>, handler: JsonRequestHandler<TContext, TPayload>, logger?: Logger): (req: Request, res: Response, next: NextFunction) => Promise<Response<TPayload>>;
|
|
82
82
|
};
|
|
83
83
|
/**
|
|
84
84
|
* Defines logic remapping a status code returned from a JsonRequestHandler in a
|
|
85
85
|
* JsonRequestHandlerResult type.
|
|
86
86
|
*/
|
|
87
|
-
export
|
|
87
|
+
export type HttpStatusCodeSelector = (httpStatusCode: undefined | number | unknown) => number;
|
|
@@ -3,4 +3,4 @@ import { ContextSelector } from '../types';
|
|
|
3
3
|
* Given a concrete ContextSelector function, infers the type of the context
|
|
4
4
|
* that it selects.
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export type ContextOf<TContextSelector extends ContextSelector<unknown>> = TContextSelector extends ContextSelector<infer U> ? U : never;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tibber-express-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -28,25 +28,25 @@
|
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@semantic-release/changelog": "^6.0.1",
|
|
30
30
|
"@semantic-release/git": "^10.0.1",
|
|
31
|
-
"@types/express": "^
|
|
31
|
+
"@types/express": "^5.0.0",
|
|
32
32
|
"@types/jest": "^28.1.6",
|
|
33
33
|
"@types/node": "^18.7.2",
|
|
34
34
|
"@types/supertest": "^2.0.12",
|
|
35
|
-
"commitizen": "^4.
|
|
35
|
+
"commitizen": "^4.3.1",
|
|
36
36
|
"conventional-commits": "^1.6.0",
|
|
37
37
|
"cz-conventional-changelog": "^3.3.0",
|
|
38
38
|
"dotenv-cli": "^6.0.0",
|
|
39
39
|
"eslint-plugin-jest": "^26.8.2",
|
|
40
40
|
"eslint-plugin-node": "^11.1.0",
|
|
41
|
-
"express": "^
|
|
41
|
+
"express": "^5.1.0",
|
|
42
42
|
"gts": "^4.0.0",
|
|
43
43
|
"husky": "^8.0.1",
|
|
44
44
|
"jest": "^28.1.3",
|
|
45
|
-
"lint-staged": "^
|
|
46
|
-
"postcss": "^8.4.
|
|
47
|
-
"semantic-release": "^
|
|
48
|
-
"sortier": "^
|
|
49
|
-
"supertest": "^
|
|
45
|
+
"lint-staged": "^15.5.1",
|
|
46
|
+
"postcss": "^8.4.38",
|
|
47
|
+
"semantic-release": "^23.0.8",
|
|
48
|
+
"sortier": "^2.0.2",
|
|
49
|
+
"supertest": "^7.0.0",
|
|
50
50
|
"ts-jest": "^28.0.7",
|
|
51
51
|
"typescript": "^4.7.4",
|
|
52
52
|
"yarn-upgrade-all": "^0.7.1"
|
|
@@ -54,6 +54,12 @@
|
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"es6-error": "^4.1.1"
|
|
56
56
|
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"express": "^5.0.0"
|
|
59
|
+
},
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": ">=18.0.0"
|
|
62
|
+
},
|
|
57
63
|
"repository": {
|
|
58
64
|
"type": "git",
|
|
59
65
|
"url": "https://github.com/tibber/tibber-express-utils.git"
|
package/readme.md
CHANGED
|
@@ -3,10 +3,15 @@
|
|
|
3
3
|
|
|
4
4
|
# Usage
|
|
5
5
|
|
|
6
|
+
## Requirements
|
|
7
|
+
|
|
8
|
+
- **Node.js**: 18 or higher
|
|
9
|
+
- **Express**: 5.x (peer dependency)
|
|
10
|
+
|
|
6
11
|
## Install
|
|
7
12
|
|
|
8
13
|
```
|
|
9
|
-
$ yarn
|
|
14
|
+
$ yarn add tibber-express-utils express@5
|
|
10
15
|
```
|
|
11
16
|
|
|
12
17
|
## Usage
|
|
@@ -76,6 +81,29 @@ In order to migrate to `3.0.0`:
|
|
|
76
81
|
1. Update `jsonRouting(express.Router(), contextSelector)` statements to `jsonRouting({contextSelector, expressRouter: express.Router()})` or
|
|
77
82
|
more preferably to `jsonRouting({contextSelector, logger, expressRouter: express.Router()})`).
|
|
78
83
|
|
|
84
|
+
## Upgrading to 4.0.0
|
|
85
|
+
|
|
86
|
+
Breaking changes in `4.0.0` include:
|
|
87
|
+
|
|
88
|
+
- **Express 5 Support**: This version now supports Express 5.x as a peer dependency.
|
|
89
|
+
- **Node.js Requirement**: Minimum Node.js version is now 18.0.0 (required by Express 5).
|
|
90
|
+
|
|
91
|
+
### Migration from 3.x.x to 4.0.0
|
|
92
|
+
|
|
93
|
+
To migrate to `4.0.0`:
|
|
94
|
+
|
|
95
|
+
1. **Update Node.js**: Ensure you're running Node.js 18 or higher.
|
|
96
|
+
2. **Update Express**: Install Express 5.x:
|
|
97
|
+
```bash
|
|
98
|
+
yarn add express@5
|
|
99
|
+
```
|
|
100
|
+
3. **Update your package**: Update tibber-express-utils to 4.x:
|
|
101
|
+
```bash
|
|
102
|
+
yarn add tibber-express-utils@4
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Note**: This library maintains the same API and doesn't use any deprecated Express features, so no code changes should be required in most cases.
|
|
106
|
+
|
|
79
107
|
# Development
|
|
80
108
|
|
|
81
109
|
Uses `gts`, Google's base `typescript` environment configuration.
|