@schmock/express 1.0.2 → 1.1.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/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -66,5 +66,4 @@ export interface ExpressAdapterOptions {
|
|
|
66
66
|
* Convert a Schmock mock instance to Express middleware
|
|
67
67
|
*/
|
|
68
68
|
export declare function toExpress(mock: CallableMockInstance, options?: ExpressAdapterOptions): RequestHandler;
|
|
69
|
-
export default toExpress;
|
|
70
69
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAM1D,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,GAAG,CAAC;IAErD;;;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;QACE,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjC,IAAI,CAAC,EAAE,GAAG,CAAC;QACX,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAChC,GACD,SAAS,GACT,OAAO,CAAC,GAAG,CAAC,CAAC;IAEjB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,CACf,eAAe,EAAE;QACf,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,GAAG,CAAC;QACV,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACjC,EACD,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,KAEX;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,GAAG,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,GAC9D,SAAS,GACT,OAAO,CACH;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,GAAG,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,GAC9D,SAAS,CACZ,CAAC;CACP;AAwED;;GAEG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,oBAAoB,EAC1B,OAAO,GAAE,qBAA0B,GAClC,cAAc,CAkFhB"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class
|
|
1
|
+
class G extends Error{code;context;constructor(T,H,U){super(T);this.code=H;this.context=U;if(this.name="SchmockError",typeof Error.captureStackTrace==="function")Error.captureStackTrace(this,this.constructor)}}var X="ROUTE_NOT_FOUND",w=["GET","POST","PUT","DELETE","PATCH","HEAD","OPTIONS"];function z(T){return w.includes(T)}function V(T){let H=T.toUpperCase();if(!z(H))throw Error(`Invalid HTTP method: "${T}"`);return H}function K(T,H){if(T.status!=null)H.status(T.status);if(T.headers)Object.entries(T.headers).forEach(([U,_])=>{if(typeof _==="string")H.set(U,_)});if(T.body!==void 0)if(typeof T.body==="string")H.send(T.body);else H.json(T.body);else H.end()}function P(T){return Object.fromEntries(Object.entries(T).map(([H,U])=>[H,Array.isArray(U)?U[0]:U||""]))}function I(T){let H={};for(let[U,_]of Object.entries(T))if(typeof _==="string")H[U]=_;else if(Array.isArray(_))H[U]=_[0]?String(_[0]):"";else if(_!=null)H[U]=String(_);return H}function u(T,H={}){let{errorFormatter:U,passErrorsToNext:_=!0,transformHeaders:Q=P,transformQuery:N=I,beforeRequest:Y,beforeResponse:Z}=H;return async(A,J,L)=>{try{let O={method:V(A.method),path:A.path,headers:Q(A.headers),body:A.body,query:N(A.query)};if(Y){let B=await Y(A,J);if(B)O={...O,...B,method:V(B.method||O.method)}}let $=await T.handle(O.method,O.path,{headers:O.headers,body:O.body,query:O.query}),W=$.body;if($.status===404&&W&&typeof W==="object"&&"code"in W&&W.code===X){L();return}if(Z){let B=await Z($,A,J);if(B)$=B}K($,J)}catch(O){if(O instanceof G&&U){let $=U(O,A);J.status(500).json($)}else if(_)L(O);else J.status(500).json({error:O instanceof Error?O.message:"Internal Server Error",code:O instanceof G?O.code:"INTERNAL_ERROR"})}}}export{u as toExpress};
|