@nest-extended/decorators 0.0.1-beta-1 → 0.0.2-beta-2
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/README.md +32 -4
- package/package.json +5 -21
- package/src/ModifyBody.decorator.d.ts +8 -0
- package/src/ModifyBody.decorator.js +20 -0
- package/src/ModifyBody.decorator.js.map +1 -0
- package/src/Public.decorator.d.ts +2 -0
- package/src/Public.decorator.js +8 -0
- package/src/Public.decorator.js.map +1 -0
- package/src/User.decorator.d.ts +1 -0
- package/src/User.decorator.js +9 -0
- package/src/User.decorator.js.map +1 -0
- package/src/index.d.ts +3 -0
- package/src/index.js +7 -0
- package/src/index.js.map +1 -0
package/README.md
CHANGED
|
@@ -1,7 +1,35 @@
|
|
|
1
|
-
# decorators
|
|
1
|
+
# @nest-extended/decorators
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This package provides useful decorators for NestJS applications.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Key Features
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- **`@User()`**: Retrieves the current user from the request (integrates with `nestjs-cls` or request object).
|
|
8
|
+
- **`@Public()`**: Marks a route as public (useful for authentication guards).
|
|
9
|
+
- **`@ModifyBody()`**: Allows modification of the request body before validation (e.g., setting `createdBy`).
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @nest-extended/decorators
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { User, Public, ModifyBody, setCreatedBy } from '@nest-extended/decorators';
|
|
21
|
+
import { Controller, Get, Post } from '@nestjs/common';
|
|
22
|
+
|
|
23
|
+
@Controller('cats')
|
|
24
|
+
export class CatsController {
|
|
25
|
+
@Public()
|
|
26
|
+
@Get()
|
|
27
|
+
findAll() { ... }
|
|
28
|
+
|
|
29
|
+
@Post()
|
|
30
|
+
create(@ModifyBody(setCreatedBy()) body: CreateDto) { ... }
|
|
31
|
+
|
|
32
|
+
@Get('profile')
|
|
33
|
+
getProfile(@User() user: any) { ... }
|
|
34
|
+
}
|
|
35
|
+
```
|
package/package.json
CHANGED
|
@@ -1,27 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nest-extended/decorators",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "0.0.2-beta-2",
|
|
5
4
|
"private": false,
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"main": "./dist/index.js",
|
|
10
|
-
"module": "./dist/index.js",
|
|
11
|
-
"types": "./dist/index.d.ts",
|
|
12
|
-
"exports": {
|
|
13
|
-
"./package.json": "./package.json",
|
|
14
|
-
".": {
|
|
15
|
-
"types": "./dist/index.d.ts",
|
|
16
|
-
"import": "./dist/index.js",
|
|
17
|
-
"default": "./dist/index.js"
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"files": [
|
|
21
|
-
"dist",
|
|
22
|
-
"!**/*.tsbuildinfo"
|
|
23
|
-
],
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"types": "./src/index.d.ts",
|
|
24
8
|
"dependencies": {
|
|
25
9
|
"tslib": "^2.3.0"
|
|
26
10
|
}
|
|
27
|
-
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Request as ExRequest } from 'express-serve-static-core';
|
|
2
|
+
declare type Request = {
|
|
3
|
+
user: any;
|
|
4
|
+
} & ExRequest;
|
|
5
|
+
declare type ModifyBodyFn = (request: Request) => Request;
|
|
6
|
+
export declare const setCreatedBy: (key?: string) => ModifyBodyFn;
|
|
7
|
+
export declare const ModifyBody: (...dataOrPipes: (ModifyBodyFn | ModifyBodyFn[] | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>> | undefined)[]) => ParameterDecorator;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModifyBody = exports.setCreatedBy = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const setCreatedBy = (key = 'createdBy') => (request) => {
|
|
6
|
+
request.body[key] = request.user._id;
|
|
7
|
+
return request;
|
|
8
|
+
};
|
|
9
|
+
exports.setCreatedBy = setCreatedBy;
|
|
10
|
+
exports.ModifyBody = (0, common_1.createParamDecorator)((fn, ctx) => {
|
|
11
|
+
const request = ctx.switchToHttp().getRequest();
|
|
12
|
+
if (Array.isArray(fn)) {
|
|
13
|
+
fn.forEach((f) => f === null || f === void 0 ? void 0 : f(request));
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
fn === null || fn === void 0 ? void 0 : fn(request);
|
|
17
|
+
}
|
|
18
|
+
return request.body;
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=ModifyBody.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModifyBody.decorator.js","sourceRoot":"","sources":["../../../../packages/decorators/src/ModifyBody.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwE;AASjE,MAAM,YAAY,GACrB,CAAC,GAAG,GAAG,WAAW,EAAgB,EAAE,CAChC,CAAC,OAAgB,EAAE,EAAE;IACjB,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;IACrC,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC;AALG,QAAA,YAAY,gBAKf;AAEG,QAAA,UAAU,GAAG,IAAA,6BAAoB,EAC1C,CAAC,EAA6C,EAAE,GAAqB,EAAE,EAAE;IACrE,MAAM,OAAO,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;IAChD,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;QACpB,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAG,OAAO,CAAC,CAAC,CAAC;IACpC,CAAC;SAAM,CAAC;QACJ,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAG,OAAO,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,OAAO,CAAC,IAAI,CAAC;AACxB,CAAC,CACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Public = exports.IS_PUBLIC_KEY = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.IS_PUBLIC_KEY = 'isPublic';
|
|
6
|
+
const Public = () => (0, common_1.SetMetadata)(exports.IS_PUBLIC_KEY, true);
|
|
7
|
+
exports.Public = Public;
|
|
8
|
+
//# sourceMappingURL=Public.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Public.decorator.js","sourceRoot":"","sources":["../../../../packages/decorators/src/Public.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAEhC,QAAA,aAAa,GAAG,UAAU,CAAC;AACjC,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,IAAA,oBAAW,EAAC,qBAAa,EAAE,IAAI,CAAC,CAAC;AAAhD,QAAA,MAAM,UAA0C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const User: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.User = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.User = (0, common_1.createParamDecorator)((data, ctx) => {
|
|
6
|
+
const request = ctx.switchToHttp().getRequest();
|
|
7
|
+
return request.user;
|
|
8
|
+
});
|
|
9
|
+
//# sourceMappingURL=User.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"User.decorator.js","sourceRoot":"","sources":["../../../../packages/decorators/src/User.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwE;AAE3D,QAAA,IAAI,GAAG,IAAA,6BAAoB,EACpC,CAAC,IAAa,EAAE,GAAqB,EAAE,EAAE;IACrC,MAAM,OAAO,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;IAChD,OAAO,OAAO,CAAC,IAAI,CAAC;AACxB,CAAC,CACJ,CAAC"}
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./ModifyBody.decorator"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./User.decorator"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./Public.decorator"), exports);
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/decorators/src/index.ts"],"names":[],"mappings":";;;AAAA,iEAAuC;AACvC,2DAAiC;AACjC,6DAAmC"}
|