@minisylar/express-typed-router 1.6.2 → 1.7.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/package.json CHANGED
@@ -1,16 +1,21 @@
1
1
  {
2
2
  "name": "@minisylar/express-typed-router",
3
- "version": "1.6.2",
3
+ "version": "1.7.0",
4
4
  "description": "A strongly-typed Express router with Zod validation and automatic type inference for params, body, query, and middleware",
5
5
  "type": "module",
6
6
  "main": "dist/schema-router.cjs",
7
- "module": "dist/schema-router.js",
8
- "types": "dist/schema-router.d.ts",
7
+ "module": "dist/schema-router.mjs",
8
+ "types": "dist/schema-router.d.mts",
9
9
  "exports": {
10
10
  ".": {
11
- "import": "./dist/schema-router.js",
12
- "require": "./dist/schema-router.cjs",
13
- "types": "./dist/schema-router.d.ts"
11
+ "import": {
12
+ "types": "./dist/schema-router.d.mts",
13
+ "default": "./dist/schema-router.mjs"
14
+ },
15
+ "require": {
16
+ "types": "./dist/schema-router.d.cts",
17
+ "default": "./dist/schema-router.cjs"
18
+ }
14
19
  }
15
20
  },
16
21
  "files": [
@@ -61,22 +66,22 @@
61
66
  "url": "https://github.com/Mini-Sylar/express-typed-router/issues"
62
67
  },
63
68
  "homepage": "https://github.com/Mini-Sylar/express-typed-router#readme",
64
- "packageManager": "pnpm@10.11.0",
69
+ "packageManager": "pnpm@11.5.0",
65
70
  "peerDependencies": {
66
71
  "express": "^4.18.0 || ^5.0.0"
67
72
  },
68
73
  "dependencies": {
69
- "@standard-schema/spec": "^1.0.0",
74
+ "@standard-schema/spec": "^1.1.0",
70
75
  "@standard-schema/utils": "^0.3.0"
71
76
  },
72
77
  "devDependencies": {
73
78
  "@semantic-release/changelog": "^6.0.3",
74
79
  "@semantic-release/git": "^10.0.1",
75
- "@types/express": "^5.0.3",
76
- "conventional-changelog-conventionalcommits": "^9.1.0",
77
- "rimraf": "^6.0.1",
78
- "semantic-release": "^24.2.7",
79
- "tsdown": "^0.14.1",
80
+ "@types/express": "^5.0.6",
81
+ "conventional-changelog-conventionalcommits": "^9.3.1",
82
+ "rimraf": "^6.1.3",
83
+ "semantic-release": "^25.0.3",
84
+ "tsdown": "^0.22.1",
80
85
  "typescript": "^5.9.2"
81
86
  },
82
87
  "engines": {
@@ -1 +0,0 @@
1
- import e from"express";import{SchemaError as t}from"@standard-schema/utils";function n(e,n){let r=e;if(r&&r[`~standard`]&&typeof r[`~standard`].validate==`function`){let e=r[`~standard`].validate(n);if(e instanceof Promise)throw TypeError(`Async schema validation is not supported by parseSchema`);if(e.issues)throw new t(e.issues);return e.value}throw TypeError(`Unsupported schema shape for parseSchema`)}function r(e,t){let n=e;if(n&&n[`~standard`]&&typeof n[`~standard`].validate==`function`)return n[`~standard`].validate(t);if(n&&typeof n.safeParse==`function`)return n.safeParse(t);if(n&&typeof n.parse==`function`)try{let e=n.parse(t);return{value:e}}catch(e){return{issues:[{message:e?.message??String(e)}]}}if(n&&typeof n.validate==`function`){let e=n.validate(t);return e&&e.then&&typeof e.then==`function`?e.then(e=>e.error?{issues:[{message:e.error.message}]}:e.issues?{issues:e.issues}:{value:e.value??e}):e&&e.error?{issues:[{message:e.error.message}]}:e&&e.issues?{issues:e.issues}:{value:e.value??e}}return{issues:[{message:`Unsupported schema shape`}]}}function i(e){return typeof e==`object`&&!!e&&`issues`in e&&Array.isArray(e.issues)}var a=class{router;constructor(){this.router=e.Router()}useMiddleware(e){return this.router.use(e),this}getRouter(){return this.router}get(e,t,n){return this.registerRoute(`get`,e,t,n)}post(e,t,n){return this.registerRoute(`post`,e,t,n)}put(e,t,n){return this.registerRoute(`put`,e,t,n)}patch(e,t,n){return this.registerRoute(`patch`,e,t,n)}delete(e,t,n){return this.registerRoute(`delete`,e,t,n)}options(e,t,n){return this.registerRoute(`options`,e,t,n)}head(e,t,n){return this.registerRoute(`head`,e,t,n)}all(e,t,n){return this.registerRoute(`all`,e,t,n)}registerRoute(e,t,n,r){let i=[];if(typeof n==`object`){let e=n;e.middleware&&i.push(...e.middleware),e.bodySchema&&i.push(this.createBodyValidationMiddleware(e.bodySchema)),e.querySchema&&i.push(this.createQueryValidationMiddleware(e.querySchema)),i.push(r)}else i.push(n);return this.router[e](t,...i),this}createBodyValidationMiddleware(e){return async(t,n,a)=>{try{let i=r(e,t.body),o=i&&typeof i.then==`function`?await i:i;if(o&&`issues`in o&&o.issues){n.status(400).json({error:`Validation failed`,details:o.errors||o.issues});return}t.body=o&&`value`in o?o.value:o,a()}catch(e){i(e)?n.status(400).json({error:`Validation failed`,details:e.errors||e.issues}):a(e)}}}createQueryValidationMiddleware(e){return async(t,n,a)=>{try{let i=r(e,t.query),o=i&&typeof i.then==`function`?await i:i;if(o&&`issues`in o&&o.issues){n.status(400).json({error:`Validation failed`,details:o.errors||o.issues});return}let s=o&&`value`in o?o.value:o;Object.defineProperty(t,`query`,{value:s,writable:!1,enumerable:!0,configurable:!0}),a()}catch(e){i(e)?n.status(400).json({error:`Validation failed`,details:e.errors||e.issues}):a(e)}}}};function o(){return new a}function s(e){let t=new a;return e?.errorHandler&&t.getRouter().use(e.errorHandler),t}function c(...e){let t=new a;for(let n of e)t=t.useMiddleware(n);return t}export{o as createTypedRouter,s as createTypedRouterWithConfig,c as createTypedRouterWithMiddleware,i as isSchemaError,n as parseSchema,r as safeParseSchema};