@schmock/express 2.0.0 → 2.0.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/dist/index.d.ts +3 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface ExpressAdapterOptions {
|
|
|
9
9
|
* @param req - Express request
|
|
10
10
|
* @returns Custom error response
|
|
11
11
|
*/
|
|
12
|
-
errorFormatter?: (error: Error, req: Request) =>
|
|
12
|
+
errorFormatter?: (error: Error, req: Request) => unknown;
|
|
13
13
|
/**
|
|
14
14
|
* Whether to pass non-Schmock errors to Express error handler
|
|
15
15
|
* @default true
|
|
@@ -33,13 +33,7 @@ export interface ExpressAdapterOptions {
|
|
|
33
33
|
* @param res - Express response
|
|
34
34
|
* @returns Modified request data or void
|
|
35
35
|
*/
|
|
36
|
-
beforeRequest?: (req: Request, res: Response) =>
|
|
37
|
-
method?: string;
|
|
38
|
-
path?: string;
|
|
39
|
-
headers?: Record<string, string>;
|
|
40
|
-
body?: any;
|
|
41
|
-
query?: Record<string, string>;
|
|
42
|
-
} | undefined | Promise<any>;
|
|
36
|
+
beforeRequest?: (req: Request, res: Response) => Schmock.AdapterRequestOverride | undefined | Promise<Schmock.AdapterRequestOverride | undefined>;
|
|
43
37
|
/**
|
|
44
38
|
* Response interceptor - called before sending response
|
|
45
39
|
* @param schmockResponse - Response from Schmock
|
|
@@ -47,19 +41,7 @@ export interface ExpressAdapterOptions {
|
|
|
47
41
|
* @param res - Express response
|
|
48
42
|
* @returns Modified response or void
|
|
49
43
|
*/
|
|
50
|
-
beforeResponse?: (schmockResponse:
|
|
51
|
-
status: number;
|
|
52
|
-
body: any;
|
|
53
|
-
headers: Record<string, string>;
|
|
54
|
-
}, req: Request, res: Response) => {
|
|
55
|
-
status: number;
|
|
56
|
-
body: any;
|
|
57
|
-
headers: Record<string, string>;
|
|
58
|
-
} | undefined | Promise<{
|
|
59
|
-
status: number;
|
|
60
|
-
body: any;
|
|
61
|
-
headers: Record<string, string>;
|
|
62
|
-
} | undefined>;
|
|
44
|
+
beforeResponse?: (schmockResponse: Schmock.Response, req: Request, res: Response) => Schmock.Response | undefined | Promise<Schmock.Response | undefined>;
|
|
63
45
|
}
|
|
64
46
|
/**
|
|
65
47
|
* Convert a Schmock mock instance to Express middleware
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAgB,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE/E;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAgB,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE/E;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC;IAEzD;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE3E;;;;OAIG;IACH,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAErE;;;;;OAKG;IACH,aAAa,CAAC,EAAE,CACd,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,KAEX,OAAO,CAAC,sBAAsB,GAC9B,SAAS,GACT,OAAO,CAAC,OAAO,CAAC,sBAAsB,GAAG,SAAS,CAAC,CAAC;IAExD;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,CACf,eAAe,EAAE,OAAO,CAAC,QAAQ,EACjC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,KACV,OAAO,CAAC,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC;CAC3E;AAqED;;GAEG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,OAAO,CAAC,oBAAoB,EAClC,OAAO,GAAE,qBAA0B,GAClC,cAAc,CAmFhB"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var T=["GET","POST","PUT","DELETE","PATCH","HEAD","OPTIONS"];function K(V){return T.includes(V)}function L(V){let $=V.toUpperCase();if(!K($))throw Error(`Invalid HTTP method: "${V}"`);return $}function z(V){let{status:$,body:J}=V;return $===404&&J!==null&&typeof J==="object"&&"code"in J&&J.code==="ROUTE_NOT_FOUND"}class A extends Error{code;context;constructor(V,$,J){super(V);this.code=$;this.context=J;if(this.name="SchmockError",typeof Error.captureStackTrace==="function")Error.captureStackTrace(this,this.constructor)}}function f(V,$){if(V.status!=null)$.status(V.status);if(V.headers)Object.entries(V.headers).forEach(([J,X])=>{if(typeof X==="string")$.set(J,X)});if(V.body!==void 0)if(typeof V.body==="string")$.send(V.body);else $.json(V.body);else $.end()}function R(V){return Object.fromEntries(Object.entries(V).map(([$,J])=>[$,Array.isArray(J)?J[0]:J]).filter(($)=>typeof $[1]==="string"))}function k(V){let $={};for(let[J,X]of Object.entries(V))if(typeof X==="string")$[J]=X;else if(Array.isArray(X))$[J]=X[0]?String(X[0]):"";else if(X!=null)$[J]=String(X);return $}function k0(V,$={}){let{errorFormatter:J,passErrorsToNext:X=!0,transformHeaders:Q=R,transformQuery:F=k,beforeRequest:B,beforeResponse:N}=$;return async(G,U,W)=>{try{let Y;try{Y=L(G.method)}catch{return W()}let Z={method:Y,path:G.path,headers:Q(G.headers),body:G.body,query:F(G.query)};if(B){let O=await B(G,U);if(O)Z={...Z,...O,method:L(O.method||Z.method)}}let _=await V.handle(Z.method,Z.path,{headers:Z.headers,body:Z.body,query:Z.query});if(z(_)){W();return}if(N){let O=await N(_,G,U);if(O)_=O}f(_,U)}catch(Y){if(Y instanceof A&&J){let Z=J(Y,G);U.status(500).json(Z)}else if(X)W(Y);else U.status(500).json({error:Y instanceof Error?Y.message:"Internal Server Error",code:Y instanceof A?Y.code:"INTERNAL_ERROR"})}}}export{k0 as toExpress};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schmock/express",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Express adapter for Schmock mock API generator",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@amiceli/vitest-cucumber": "^6.
|
|
31
|
+
"@amiceli/vitest-cucumber": "^6.5.0",
|
|
32
32
|
"@types/express": "^5.0.6",
|
|
33
|
-
"@types/node": "^25.
|
|
33
|
+
"@types/node": "^25.8.0",
|
|
34
34
|
"express": "^5.2.1",
|
|
35
|
-
"typescript": "^6.0.
|
|
36
|
-
"vitest": "^4.1.
|
|
35
|
+
"typescript": "^6.0.3",
|
|
36
|
+
"vitest": "^4.1.6"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@schmock/core": "^2.0.
|
|
39
|
+
"@schmock/core": "^2.0.2",
|
|
40
40
|
"express": "^4.18.0 || ^5.0.0"
|
|
41
41
|
},
|
|
42
42
|
"keywords": [
|