@ts-typed/nestjs 0.0.1 → 0.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/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,17 @@ All notable changes to `@ts-typed/nestjs` are documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [0.1.0] - 2026-10-17
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- `StrictTypeErrorFilter` returned HTTP 400 for every `StrictTypeError`, including one raised while validating a function or method's own return value (for example, a mapper reading a corrupted row out of the database) — a server-side failure, not a bad request. A violation whose `operation` is `return` or `resolve` now maps to HTTP 500; every other operation (`argument`, `set`, `initialize`, …) keeps the existing 400.
|
|
12
|
+
- The package's `exports` map did not expose `./package.json`, breaking `require.resolve('@ts-typed/nestjs/package.json')` and similar version-probing patterns.
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- Depends on `@ts-typed/compiler@0.1.0`, whose changelog covers the coverage gaps (class methods/constructors, decorated fields, `Date`) that this package's own tests exercise against a real NestJS app.
|
|
17
|
+
|
|
7
18
|
## [0.0.1] - 2026-10-16
|
|
8
19
|
|
|
9
20
|
Initial release.
|
|
@@ -2,13 +2,13 @@ import type { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
|
|
|
2
2
|
import { StrictTypeError } from '@ts-typed/compiler';
|
|
3
3
|
/**
|
|
4
4
|
* Translates a `StrictTypeError` thrown by instrumented code (a DTO/provider
|
|
5
|
-
* field failing validation at a protected boundary) into
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
5
|
+
* field failing validation at a protected boundary) into an HTTP response,
|
|
6
|
+
* using `StrictTypeError#toJSON()`'s already-safe payload (no raw received
|
|
7
|
+
* value, no stack). Register it the same way as any other Nest exception
|
|
8
|
+
* filter (`@UseFilters(StrictTypeErrorFilter)` or as a global `APP_FILTER`
|
|
9
|
+
* provider); it does not replace Nest's own validation pipes or instantiate
|
|
10
|
+
* DTOs — it only reacts to an error ts-typed's own instrumented code already
|
|
11
|
+
* threw.
|
|
12
12
|
*/
|
|
13
13
|
export declare class StrictTypeErrorFilter implements ExceptionFilter {
|
|
14
14
|
catch(exception: StrictTypeError, host: ArgumentsHost): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strict-type-error.filter.d.ts","sourceRoot":"","sources":["../src/strict-type-error.filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAErE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"strict-type-error.filter.d.ts","sourceRoot":"","sources":["../src/strict-type-error.filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAErE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAkBrD;;;;;;;;;GASG;AACH,qBACa,qBAAsB,YAAW,eAAe;IACpD,KAAK,CAAC,SAAS,EAAE,eAAe,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI;CAYpE"}
|
|
@@ -9,24 +9,37 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.StrictTypeErrorFilter = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const compiler_1 = require("@ts-typed/compiler");
|
|
12
|
+
/**
|
|
13
|
+
* A `return`/`resolve` violation means the function or method's OWN body
|
|
14
|
+
* produced a value that fails its declared return type — e.g. a mapper
|
|
15
|
+
* reading a corrupted row out of the database. The client did nothing wrong
|
|
16
|
+
* at that boundary, so it is a server-side failure (500), not a bad request
|
|
17
|
+
* (400). Every other operation (`argument`, `set`, `initialize`, …) reflects
|
|
18
|
+
* a value that came from outside the function at that exact validation
|
|
19
|
+
* point — closer to client-controlled input — and keeps the 400 default.
|
|
20
|
+
*/
|
|
21
|
+
const SERVER_FAULT_OPERATIONS = new Set(['return', 'resolve']);
|
|
12
22
|
/**
|
|
13
23
|
* Translates a `StrictTypeError` thrown by instrumented code (a DTO/provider
|
|
14
|
-
* field failing validation at a protected boundary) into
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
24
|
+
* field failing validation at a protected boundary) into an HTTP response,
|
|
25
|
+
* using `StrictTypeError#toJSON()`'s already-safe payload (no raw received
|
|
26
|
+
* value, no stack). Register it the same way as any other Nest exception
|
|
27
|
+
* filter (`@UseFilters(StrictTypeErrorFilter)` or as a global `APP_FILTER`
|
|
28
|
+
* provider); it does not replace Nest's own validation pipes or instantiate
|
|
29
|
+
* DTOs — it only reacts to an error ts-typed's own instrumented code already
|
|
30
|
+
* threw.
|
|
21
31
|
*/
|
|
22
32
|
let StrictTypeErrorFilter = class StrictTypeErrorFilter {
|
|
23
33
|
catch(exception, host) {
|
|
24
34
|
const response = host.switchToHttp().getResponse();
|
|
35
|
+
const status = SERVER_FAULT_OPERATIONS.has(exception.operation)
|
|
36
|
+
? common_1.HttpStatus.INTERNAL_SERVER_ERROR
|
|
37
|
+
: common_1.HttpStatus.BAD_REQUEST;
|
|
25
38
|
const httpException = new common_1.HttpException({
|
|
26
|
-
statusCode:
|
|
39
|
+
statusCode: status,
|
|
27
40
|
message: exception.message,
|
|
28
41
|
...exception.toJSON(),
|
|
29
|
-
},
|
|
42
|
+
}, status);
|
|
30
43
|
response.status(httpException.getStatus()).json(httpException.getResponse());
|
|
31
44
|
}
|
|
32
45
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strict-type-error.filter.js","sourceRoot":"","sources":["../src/strict-type-error.filter.ts"],"names":[],"mappings":";;;;;;;;;AACA,2CAAkE;AAClE,iDAAqD;AAOrD;;;;;;;;;GASG;AAEI,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IACzB,KAAK,CAAC,SAA0B,EAAE,IAAmB;QAC1D,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC,WAAW,EAAuB,CAAC;QACxE,MAAM,aAAa,GAAG,IAAI,sBAAa,CAAC;YACtC,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"strict-type-error.filter.js","sourceRoot":"","sources":["../src/strict-type-error.filter.ts"],"names":[],"mappings":";;;;;;;;;AACA,2CAAkE;AAClE,iDAAqD;AAOrD;;;;;;;;GAQG;AACH,MAAM,uBAAuB,GAAwB,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;AAEpF;;;;;;;;;GASG;AAEI,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IACzB,KAAK,CAAC,SAA0B,EAAE,IAAmB;QAC1D,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC,WAAW,EAAuB,CAAC;QACxE,MAAM,MAAM,GAAG,uBAAuB,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC;YAC7D,CAAC,CAAC,mBAAU,CAAC,qBAAqB;YAClC,CAAC,CAAC,mBAAU,CAAC,WAAW,CAAC;QAC3B,MAAM,aAAa,GAAG,IAAI,sBAAa,CAAC;YACtC,UAAU,EAAE,MAAM;YAClB,OAAO,EAAE,SAAS,CAAC,OAAO;YAC1B,GAAG,SAAS,CAAC,MAAM,EAAE;SACtB,EAAE,MAAM,CAAC,CAAC;QACX,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC,CAAC;IAC/E,CAAC;CACF,CAAA;AAbY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,cAAK,EAAC,0BAAe,CAAC;GACV,qBAAqB,CAajC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-typed/nestjs",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"types": "./dist/index.d.ts",
|
|
18
18
|
"require": "./dist/index.js",
|
|
19
19
|
"default": "./dist/index.js"
|
|
20
|
-
}
|
|
20
|
+
},
|
|
21
|
+
"./package.json": "./package.json"
|
|
21
22
|
},
|
|
22
23
|
"files": [
|
|
23
24
|
"dist",
|
|
@@ -32,7 +33,7 @@
|
|
|
32
33
|
"test": "npm run build && node --test --test-concurrency=1"
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
35
|
-
"@ts-typed/compiler": "0.0
|
|
36
|
+
"@ts-typed/compiler": "0.1.0"
|
|
36
37
|
},
|
|
37
38
|
"peerDependencies": {
|
|
38
39
|
"@nestjs/common": ">=10 <13",
|