@sebspark/openapi-express 5.0.9 → 5.0.10
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.mts +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -9
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { APIServerDefinition, APIServerOptions } from "@sebspark/openapi-core";
|
|
2
|
-
import
|
|
2
|
+
import { Router } from "express";
|
|
3
3
|
|
|
4
4
|
//#region src/router.d.ts
|
|
5
|
-
declare const TypedRouter: (api: APIServerDefinition, options?: APIServerOptions) =>
|
|
5
|
+
declare const TypedRouter: (api: APIServerDefinition, options?: APIServerOptions) => Router;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { TypedRouter };
|
|
8
8
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/router.ts"],"sourcesContent":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/router.ts"],"sourcesContent":[],"mappings":";;;;cAkBa,mBACN,+BACI,qBACR"}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/router.ts"],"sourcesContent":["import {\n type APIResponse,\n type APIServerDefinition,\n type APIServerOptions,\n createHttpError,\n type HttpError,\n type Verb,\n} from '@sebspark/openapi-core'\nimport {\n type ErrorRequestHandler,\n json,\n type NextFunction,\n type Request,\n type RequestHandler,\n type Response,\n Router,\n} from 'express'\n\nexport const TypedRouter = (\n api: APIServerDefinition,\n options: APIServerOptions = {}\n): Router => {\n const router = Router()\n\n router.use(json() as unknown as RequestHandler)\n\n // Add global pre to router\n const preUsings = Array.isArray(options.pre)\n ? options.pre\n : options.pre\n ? [options.pre]\n : []\n for (const pre of preUsings) {\n router.use(pre)\n }\n\n // loop through urls on server definition\n for (const [url, methods] of Object.entries(api)) {\n // loop through methods on url\n for (const [method, route] of Object.entries(methods)) {\n // Build handler for url/method\n const handler = async (\n req: Request,\n res: Response,\n next: NextFunction\n ) => {\n try {\n const [status, response] = await route.handler(req)\n res.status(status)\n\n if (!response) {\n res.end()\n return\n }\n\n const { headers, data } = response as APIResponse<\n unknown,\n Record<string, string>\n >\n\n if (headers) {\n for (const [name, value] of Object.entries(headers)) {\n res.setHeader(name, value)\n }\n }\n\n if (data) {\n res.send(data)\n } else {\n res.end()\n }\n } catch (error) {\n next(error)\n }\n }\n\n const pre = Array.isArray(route.pre)\n ? route.pre\n : route.pre\n ? [route.pre]\n : []\n const handlers = pre.concat(handler as RequestHandler)\n\n router[method as Verb](url, ...handlers)\n }\n }\n\n router.use(errorHandler)\n\n return router\n}\n\nconst errorHandler: ErrorRequestHandler = (err, _req, res, next) => {\n let error: HttpError = err\n\n if (!error.message || !error.statusCode) {\n const internal =\n err instanceof Error\n ? err\n : typeof err === 'string'\n ? new Error(err)\n : new Error(JSON.stringify(err || ''))\n error = createHttpError(500, undefined, internal)\n }\n\n const showStack = process.env.NODE_ENV !== 'production'\n res.status(error.statusCode).send(error.toJSON(showStack))\n next(error)\n}\n"],"mappings":";;;;AAkBA,MAAa,eACX,KACA,UAA4B,EAAE,KACnB;CACX,MAAM,SAAS,QAAQ;AAEvB,QAAO,IAAI,MAAM,CAA8B;CAG/C,MAAM,YAAY,MAAM,QAAQ,QAAQ,IAAI,GACxC,QAAQ,MACR,QAAQ,MACN,CAAC,QAAQ,IAAI,GACb,EAAE;AACR,MAAK,MAAM,OAAO,UAChB,QAAO,IAAI,IAAI;AAIjB,MAAK,MAAM,CAAC,KAAK,YAAY,OAAO,QAAQ,IAAI,CAE9C,MAAK,MAAM,CAAC,QAAQ,UAAU,OAAO,QAAQ,QAAQ,EAAE;EAErD,MAAM,UAAU,OACd,KACA,KACA,SACG;AACH,OAAI;IACF,MAAM,CAAC,QAAQ,YAAY,MAAM,MAAM,QAAQ,IAAI;AACnD,QAAI,OAAO,OAAO;AAElB,QAAI,CAAC,UAAU;AACb,SAAI,KAAK;AACT;;IAGF,MAAM,EAAE,SAAS,SAAS;AAK1B,QAAI,QACF,MAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,QAAQ,CACjD,KAAI,UAAU,MAAM,MAAM;AAI9B,QAAI,KACF,KAAI,KAAK,KAAK;QAEd,KAAI,KAAK;YAEJ,OAAO;AACd,SAAK,MAAM;;;EASf,MAAM,YALM,MAAM,QAAQ,MAAM,IAAI,GAChC,MAAM,MACN,MAAM,MACJ,CAAC,MAAM,IAAI,GACX,EAAE,EACa,OAAO,QAA0B;AAEtD,SAAO,QAAgB,KAAK,GAAG,SAAS;;AAI5C,QAAO,IAAI,aAAa;AAExB,QAAO;;AAGT,MAAM,gBAAqC,KAAK,MAAM,KAAK,SAAS;CAClE,IAAI,QAAmB;AAEvB,KAAI,CAAC,MAAM,WAAW,CAAC,MAAM,WAO3B,SAAQ,gBAAgB,KAAK,QAL3B,eAAe,QACX,MACA,OAAO,QAAQ,WACb,IAAI,MAAM,IAAI,GACd,IAAI,MAAM,KAAK,UAAU,OAAO,GAAG,CAAC,CACK;CAGnD,MAAM,YAAY,QAAQ,IAAI,aAAa;AAC3C,KAAI,OAAO,MAAM,WAAW,CAAC,KAAK,MAAM,OAAO,UAAU,CAAC;AAC1D,MAAK,MAAM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sebspark/openapi-express",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.10",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -23,19 +23,15 @@
|
|
|
23
23
|
"typecheck": "vitest --typecheck.only --passWithNoTests"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@sebspark/otel": "
|
|
27
|
-
"@sebspark/tsconfig": "
|
|
26
|
+
"@sebspark/otel": "2.0.10",
|
|
27
|
+
"@sebspark/tsconfig": "3.0.5",
|
|
28
28
|
"@types/supertest": "6.0.3",
|
|
29
29
|
"express": "5.2.1",
|
|
30
|
-
"supertest": "7.
|
|
30
|
+
"supertest": "7.2.2",
|
|
31
31
|
"vitest": "4.0.16"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@sebspark/openapi-core": "
|
|
35
|
-
"@types/express-serve-static-core": "5.1.0",
|
|
34
|
+
"@sebspark/openapi-core": "4.0.12",
|
|
36
35
|
"express": "5.2.1"
|
|
37
|
-
},
|
|
38
|
-
"peerDependencies": {
|
|
39
|
-
"@sebspark/otel": ">=2.0.9"
|
|
40
36
|
}
|
|
41
37
|
}
|