@schmock/express 1.2.2 → 1.4.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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +4 -3
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var Q="ROUTE_NOT_FOUND",O=["GET","POST","PUT","DELETE","PATCH","HEAD","OPTIONS"];function F(A){return O.includes(A)}function G(A){let B=A.toUpperCase();if(!F(B))throw Error(`Invalid HTTP method: "${A}"`);return B}class $ extends Error{code;context;constructor(A,B,V){super(A);this.code=B;this.context=V;if(this.name="SchmockError",typeof Error.captureStackTrace==="function")Error.captureStackTrace(this,this.constructor)}}function M(A,B){if(A.status!=null)B.status(A.status);if(A.headers)Object.entries(A.headers).forEach(([V,W])=>{if(typeof W==="string")B.set(V,W)});if(A.body!==void 0)if(typeof A.body==="string")B.send(A.body);else B.json(A.body);else B.end()}function P(A){return Object.fromEntries(Object.entries(A).map(([B,V])=>[B,Array.isArray(V)?V[0]:V||""]))}function S(A){let B={};for(let[V,W]of Object.entries(A))if(typeof W==="string")B[V]=W;else if(Array.isArray(W))B[V]=W[0]?String(W[0]):"";else if(W!=null)B[V]=String(W);return B}function a(A,B={}){let{errorFormatter:V,passErrorsToNext:W=!0,transformHeaders:H=P,transformQuery:N=S,beforeRequest:U,beforeResponse:w}=B;return async(X,z,_)=>{try{let J={method:G(X.method),path:X.path,headers:H(X.headers),body:X.body,query:N(X.query)};if(U){let Z=await U(X,z);if(Z)J={...J,...Z,method:G(Z.method||J.method)}}let Y=await A.handle(J.method,J.path,{headers:J.headers,body:J.body,query:J.query}),L=Y.body;if(Y.status===404&&L&&typeof L==="object"&&"code"in L&&L.code===Q){_();return}if(w){let Z=await w(Y,X,z);if(Z)Y=Z}M(Y,z)}catch(J){if(J instanceof $&&V){let Y=V(J,X);z.status(500).json(Y)}else if(W)_(J);else z.status(500).json({error:J instanceof Error?J.message:"Internal Server Error",code:J instanceof $?J.code:"INTERNAL_ERROR"})}}}export{a as toExpress};
1
+ var Q="ROUTE_NOT_FOUND",w=["GET","POST","PUT","DELETE","PATCH","HEAD","OPTIONS"];function F(A){return w.includes(A)}function B(A){let J=A.toUpperCase();if(!F(J))throw Error(`Invalid HTTP method: "${A}"`);return J}class z extends Error{code;context;constructor(A,J,W){super(A);this.code=J;this.context=W;if(this.name="SchmockError",typeof Error.captureStackTrace==="function")Error.captureStackTrace(this,this.constructor)}}function D(A,J){if(A.status!=null)J.status(A.status);if(A.headers)Object.entries(A.headers).forEach(([W,X])=>{if(typeof X==="string")J.set(W,X)});if(A.body!==void 0)if(typeof A.body==="string")J.send(A.body);else J.json(A.body);else J.end()}function P(A){return Object.fromEntries(Object.entries(A).map(([J,W])=>[J,Array.isArray(W)?W[0]:W||""]))}function x(A){let J={};for(let[W,X]of Object.entries(A))if(typeof X==="string")J[W]=X;else if(Array.isArray(X))J[W]=X[0]?String(X[0]):"";else if(X!=null)J[W]=String(X);return J}function a(A,J={}){let{errorFormatter:W,passErrorsToNext:X=!0,transformHeaders:N=P,transformQuery:j=x,beforeRequest:U,beforeResponse:_}=J;return async(Y,G,O)=>{try{let V={method:B(Y.method),path:Y.path,headers:N(Y.headers),body:Y.body,query:j(Y.query)};if(U){let $=await U(Y,G);if($)V={...V,...$,method:B($.method||V.method)}}let Z=await A.handle(V.method,V.path,{headers:V.headers,body:V.body,query:V.query}),L=Z.body;if(Z.status===404&&L&&typeof L==="object"&&"code"in L&&L.code===Q){O();return}if(_){let $=await _(Z,Y,G);if($)Z=$}D(Z,G)}catch(V){if(V instanceof z&&W){let Z=W(V,Y);G.status(500).json(Z)}else if(X)O(V);else G.status(500).json({error:V instanceof Error?V.message:"Internal Server Error",code:V instanceof z?V.code:"INTERNAL_ERROR"})}}}export{a as toExpress};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schmock/express",
3
- "version": "1.2.2",
3
+ "version": "1.4.0",
4
4
  "description": "Express adapter for Schmock mock API generator",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -9,14 +9,15 @@
9
9
  ".": {
10
10
  "types": "./dist/index.d.ts",
11
11
  "import": "./dist/index.js"
12
- }
12
+ },
13
+ "./package.json": "./package.json"
13
14
  },
14
15
  "files": [
15
16
  "dist"
16
17
  ],
17
18
  "scripts": {
18
19
  "build": "bun build:lib && bun build:types",
19
- "build:lib": "bun build --minify --outdir=dist src/index.ts",
20
+ "build:lib": "bun build --minify --target node --outdir=dist src/index.ts",
20
21
  "build:types": "tsc -p tsconfig.json",
21
22
  "test": "vitest",
22
23
  "test:watch": "vitest --watch",