@nest-extended/core 0.0.1-beta-1 → 0.0.1-beta-8
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 +43 -4
- package/package.json +5 -21
- package/src/common/cls.helper.d.ts +13 -0
- package/src/common/cls.helper.js +28 -0
- package/src/common/cls.helper.js.map +1 -0
- package/src/common/constants.d.ts +10 -0
- package/src/common/constants.js +15 -0
- package/src/common/constants.js.map +1 -0
- package/src/common/decorators/ModifyBody.decorator.d.ts +8 -0
- package/src/common/decorators/ModifyBody.decorator.js +20 -0
- package/src/common/decorators/ModifyBody.decorator.js.map +1 -0
- package/src/common/decorators/Public.decorator.d.ts +2 -0
- package/src/common/decorators/Public.decorator.js +8 -0
- package/src/common/decorators/Public.decorator.js.map +1 -0
- package/src/common/decorators/User.decorator.d.ts +1 -0
- package/src/common/decorators/User.decorator.js +9 -0
- package/src/common/decorators/User.decorator.js.map +1 -0
- package/src/common/options.d.ts +11 -0
- package/src/common/options.js +13 -0
- package/src/common/options.js.map +1 -0
- package/src/index.d.ts +11 -0
- package/src/index.js +17 -0
- package/src/index.js.map +1 -0
- package/src/lib/core.d.ts +1 -0
- package/src/lib/core.js +7 -0
- package/src/lib/core.js.map +1 -0
- package/src/lib/nest-extended.module.d.ts +5 -0
- package/src/lib/nest-extended.module.js +27 -0
- package/src/lib/nest-extended.module.js.map +1 -0
- package/src/lib/nest.controller.d.ts +12 -0
- package/src/lib/nest.controller.js +82 -0
- package/src/lib/nest.controller.js.map +1 -0
- package/src/types/PaginatedResponse.d.ts +6 -0
- package/src/types/PaginatedResponse.js +3 -0
- package/src/types/PaginatedResponse.js.map +1 -0
- package/src/types/ServiceOptions.d.ts +12 -0
- package/src/types/ServiceOptions.js +3 -0
- package/src/types/ServiceOptions.js.map +1 -0
- package/src/types/nest-extended.config.d.ts +30 -0
- package/src/types/nest-extended.config.js +9 -0
- package/src/types/nest-extended.config.js.map +1 -0
package/README.md
CHANGED
|
@@ -1,7 +1,46 @@
|
|
|
1
|
-
# core
|
|
1
|
+
# @nest-extended/core
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This package provides the core building blocks for NestJS applications built with the **NestExtended** ecosystem. It includes generic controllers, decorators, and configuration interfaces designed to work seamlessly with `@nest-extended/mongoose`.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Key Features
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- **Generic Controller (`NestController`)**: A base controller class that handles common CRUD operations (`find`, `get`, `create`, `patch`, `delete`) by delegating to a service implementing `ServiceOptions`.
|
|
8
|
+
- **Decorators**:
|
|
9
|
+
- `@User()`: Retrieves the current user from the request (integrates with `nestjs-cls` or request object).
|
|
10
|
+
- `@Public()`: Marks a route as public (useful for authentication guards).
|
|
11
|
+
- `@ModifyBody()`: Allows modification of the request body before validation (e.g., setting `createdBy`).
|
|
12
|
+
- **Configuration**: Interfaces for configuring soft delete behavior and other service options.
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
### NestController
|
|
17
|
+
|
|
18
|
+
Extend `NestController` to automatically expose standard CRUD endpoints.
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { NestController } from '@nest-extended/core';
|
|
22
|
+
import { MyService } from './my.service';
|
|
23
|
+
|
|
24
|
+
@Controller('my-resource')
|
|
25
|
+
export class MyController extends NestController<MyResource> {
|
|
26
|
+
constructor(private readonly myService: MyService) {
|
|
27
|
+
super(myService);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Decorators
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { User, Public, ModifyBody, setCreatedBy } from '@nest-extended/core';
|
|
36
|
+
|
|
37
|
+
@Public()
|
|
38
|
+
@Get()
|
|
39
|
+
findAll() { ... }
|
|
40
|
+
|
|
41
|
+
@Post()
|
|
42
|
+
create(@ModifyBody(setCreatedBy()) body: CreateDto) { ... }
|
|
43
|
+
|
|
44
|
+
@Get('profile')
|
|
45
|
+
getProfile(@User() user: any) { ... }
|
|
46
|
+
```
|
package/package.json
CHANGED
|
@@ -1,27 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nest-extended/core",
|
|
3
|
-
"version": "0.0.1-beta-
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "0.0.1-beta-8",
|
|
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,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants for CLS keys used in the application.
|
|
3
|
+
*/
|
|
4
|
+
export declare const CLS_KEYS: {
|
|
5
|
+
readonly USER: "user";
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Get the current user from the CLS (Continuation Local Storage) context.
|
|
9
|
+
* This user is set by the AuthGuard after successful token verification.
|
|
10
|
+
*
|
|
11
|
+
* @returns The current authenticated user, or undefined if not available
|
|
12
|
+
*/
|
|
13
|
+
export declare function getCurrentUser<T = any>(): T | undefined;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CLS_KEYS = void 0;
|
|
4
|
+
exports.getCurrentUser = getCurrentUser;
|
|
5
|
+
const nestjs_cls_1 = require("nestjs-cls");
|
|
6
|
+
/**
|
|
7
|
+
* Constants for CLS keys used in the application.
|
|
8
|
+
*/
|
|
9
|
+
exports.CLS_KEYS = {
|
|
10
|
+
USER: 'user',
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Get the current user from the CLS (Continuation Local Storage) context.
|
|
14
|
+
* This user is set by the AuthGuard after successful token verification.
|
|
15
|
+
*
|
|
16
|
+
* @returns The current authenticated user, or undefined if not available
|
|
17
|
+
*/
|
|
18
|
+
function getCurrentUser() {
|
|
19
|
+
try {
|
|
20
|
+
const cls = nestjs_cls_1.ClsServiceManager.getClsService();
|
|
21
|
+
return cls === null || cls === void 0 ? void 0 : cls.get(exports.CLS_KEYS.USER);
|
|
22
|
+
}
|
|
23
|
+
catch (_a) {
|
|
24
|
+
// CLS context may not be available (e.g., during app startup)
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=cls.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cls.helper.js","sourceRoot":"","sources":["../../../../../packages/core/src/common/cls.helper.ts"],"names":[],"mappings":";;;AAeA,wCAQC;AAvBD,2CAA+C;AAE/C;;GAEG;AACU,QAAA,QAAQ,GAAG;IACpB,IAAI,EAAE,MAAM;CACN,CAAC;AAEX;;;;;GAKG;AACH,SAAgB,cAAc;IAC1B,IAAI,CAAC;QACD,MAAM,GAAG,GAAG,8BAAiB,CAAC,aAAa,EAAE,CAAC;QAC9C,OAAO,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,GAAG,CAAC,gBAAQ,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAAC,WAAM,CAAC;QACL,8DAA8D;QAC9D,OAAO,SAAS,CAAC;IACrB,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EachSlotDurationInMinutes = exports.WeekDays = void 0;
|
|
4
|
+
var WeekDays;
|
|
5
|
+
(function (WeekDays) {
|
|
6
|
+
WeekDays["sunday"] = "sunday";
|
|
7
|
+
WeekDays["monday"] = "monday";
|
|
8
|
+
WeekDays["tuesday"] = "tuesday";
|
|
9
|
+
WeekDays["wednesday"] = "wednesday";
|
|
10
|
+
WeekDays["thursday"] = "thursday";
|
|
11
|
+
WeekDays["friday"] = "friday";
|
|
12
|
+
WeekDays["saturday"] = "saturday";
|
|
13
|
+
})(WeekDays || (exports.WeekDays = WeekDays = {}));
|
|
14
|
+
exports.EachSlotDurationInMinutes = 30;
|
|
15
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../packages/core/src/common/constants.ts"],"names":[],"mappings":";;;AAAA,IAAY,QAQT;AARH,WAAY,QAAQ;IAChB,6BAAiB,CAAA;IACjB,6BAAiB,CAAA;IACjB,+BAAmB,CAAA;IACnB,mCAAuB,CAAA;IACvB,iCAAqB,CAAA;IACrB,6BAAiB,CAAA;IACjB,iCAAqB,CAAA;AACvB,CAAC,EARS,QAAQ,wBAAR,QAAQ,QAQjB;AAEY,QAAA,yBAAyB,GAAG,EAAE,CAAC"}
|
|
@@ -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/core/src/common/decorators/ModifyBody.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwE;AAUjE,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/core/src/common/decorators/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/core/src/common/decorators/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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Warning: Modify this properly!
|
|
5
|
+
*/
|
|
6
|
+
exports.default = {
|
|
7
|
+
deleteKey: 'deleted',
|
|
8
|
+
defaultPagination: true,
|
|
9
|
+
defaultLimit: 20,
|
|
10
|
+
defaultSkip: 0,
|
|
11
|
+
multi: false,
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../../../../packages/core/src/common/options.ts"],"names":[],"mappings":";;AAAA;;GAEG;AACH,kBAAe;IACX,SAAS,EAAE,SAAS;IACpB,iBAAiB,EAAE,IAAI;IACvB,YAAY,EAAE,EAAE;IAChB,WAAW,EAAE,CAAC;IACd,KAAK,EAAE,KAAK;CACf,CAAC"}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './lib/core';
|
|
2
|
+
export * from './lib/nest.controller';
|
|
3
|
+
export * from './lib/nest-extended.module';
|
|
4
|
+
export { default as options } from './common/options';
|
|
5
|
+
export * from './common/decorators/ModifyBody.decorator';
|
|
6
|
+
export * from './common/decorators/Public.decorator';
|
|
7
|
+
export * from './common/decorators/User.decorator';
|
|
8
|
+
export * from './common/cls.helper';
|
|
9
|
+
export * from './types/nest-extended.config';
|
|
10
|
+
export * from './types/PaginatedResponse';
|
|
11
|
+
export * from './types/ServiceOptions';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.options = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
tslib_1.__exportStar(require("./lib/core"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./lib/nest.controller"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./lib/nest-extended.module"), exports);
|
|
8
|
+
var options_1 = require("./common/options");
|
|
9
|
+
Object.defineProperty(exports, "options", { enumerable: true, get: function () { return options_1.default; } });
|
|
10
|
+
tslib_1.__exportStar(require("./common/decorators/ModifyBody.decorator"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./common/decorators/Public.decorator"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./common/decorators/User.decorator"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./common/cls.helper"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./types/nest-extended.config"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./types/PaginatedResponse"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./types/ServiceOptions"), exports);
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/core/src/index.ts"],"names":[],"mappings":";;;;AAAA,qDAA2B;AAC3B,gEAAsC;AACtC,qEAA2C;AAC3C,4CAAsD;AAA7C,kGAAA,OAAO,OAAW;AAC3B,mFAAyD;AACzD,+EAAqD;AACrD,6EAAmD;AACnD,8DAAoC;AACpC,uEAA6C;AAC7C,oEAA0C;AAC1C,iEAAuC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function core(): string;
|
package/src/lib/core.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../../../packages/core/src/lib/core.ts"],"names":[],"mappings":";;AAAA,oBAEC;AAFD,SAAgB,IAAI;IAClB,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var NestExtendedModule_1;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.NestExtendedModule = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
const nest_extended_config_1 = require("../types/nest-extended.config");
|
|
8
|
+
let NestExtendedModule = NestExtendedModule_1 = class NestExtendedModule {
|
|
9
|
+
static forRoot(config = {}) {
|
|
10
|
+
return {
|
|
11
|
+
module: NestExtendedModule_1,
|
|
12
|
+
global: true,
|
|
13
|
+
providers: [
|
|
14
|
+
{
|
|
15
|
+
provide: nest_extended_config_1.NEST_EXTENDED_CONFIG,
|
|
16
|
+
useValue: config,
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
exports: [nest_extended_config_1.NEST_EXTENDED_CONFIG],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.NestExtendedModule = NestExtendedModule;
|
|
24
|
+
exports.NestExtendedModule = NestExtendedModule = NestExtendedModule_1 = tslib_1.__decorate([
|
|
25
|
+
(0, common_1.Module)({})
|
|
26
|
+
], NestExtendedModule);
|
|
27
|
+
//# sourceMappingURL=nest-extended.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nest-extended.module.js","sourceRoot":"","sources":["../../../../../packages/core/src/lib/nest-extended.module.ts"],"names":[],"mappings":";;;;;AAAA,2CAAuD;AACvD,wEAAyF;AAGlF,IAAM,kBAAkB,0BAAxB,MAAM,kBAAkB;IAC3B,MAAM,CAAC,OAAO,CAAC,SAA6B,EAAE;QAC1C,OAAO;YACH,MAAM,EAAE,oBAAkB;YAC1B,MAAM,EAAE,IAAI;YACZ,SAAS,EAAE;gBACP;oBACI,OAAO,EAAE,2CAAoB;oBAC7B,QAAQ,EAAE,MAAM;iBACnB;aACJ;YACD,OAAO,EAAE,CAAC,2CAAoB,CAAC;SAClC,CAAC;IACN,CAAC;CACJ,CAAA;AAdY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,kBAAkB,CAc9B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Logger } from '@nestjs/common';
|
|
2
|
+
import { ServiceOptions } from '../types/ServiceOptions';
|
|
3
|
+
export declare class NestController<T> {
|
|
4
|
+
private readonly service;
|
|
5
|
+
protected readonly logger: Logger;
|
|
6
|
+
constructor(service: ServiceOptions<T>);
|
|
7
|
+
find(query: Record<string, any>): Promise<any>;
|
|
8
|
+
get(query: Record<string, any>, id: string): Promise<any>;
|
|
9
|
+
create(createDto: T): Promise<any>;
|
|
10
|
+
patch(query: Record<string, any>, patchDto: Partial<T>, id: string): Promise<any>;
|
|
11
|
+
delete(id: string, query: Record<string, any>, user: any): Promise<any>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NestController = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const Public_decorator_1 = require("../common/decorators/Public.decorator");
|
|
7
|
+
const User_decorator_1 = require("../common/decorators/User.decorator");
|
|
8
|
+
const ModifyBody_decorator_1 = require("../common/decorators/ModifyBody.decorator");
|
|
9
|
+
class NestController {
|
|
10
|
+
constructor(service) {
|
|
11
|
+
this.service = service;
|
|
12
|
+
this.logger = new common_1.Logger(NestController.name);
|
|
13
|
+
}
|
|
14
|
+
find(query) {
|
|
15
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
return yield this.service._find(query);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
get(query, id) {
|
|
20
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
return yield this.service._get(id, query);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
create(createDto) {
|
|
25
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
return yield this.service._create(createDto);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
patch(query, patchDto, id) {
|
|
30
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
return yield this.service._patch(id, patchDto, query);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
delete(id, query, user) {
|
|
35
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
return yield this.service._remove(id, query, user);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.NestController = NestController;
|
|
41
|
+
tslib_1.__decorate([
|
|
42
|
+
(0, Public_decorator_1.Public)(),
|
|
43
|
+
(0, common_1.Get)(),
|
|
44
|
+
tslib_1.__param(0, (0, common_1.Query)()),
|
|
45
|
+
tslib_1.__metadata("design:type", Function),
|
|
46
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
47
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
48
|
+
], NestController.prototype, "find", null);
|
|
49
|
+
tslib_1.__decorate([
|
|
50
|
+
(0, common_1.Get)('/:id?'),
|
|
51
|
+
tslib_1.__param(0, (0, common_1.Query)()),
|
|
52
|
+
tslib_1.__param(1, (0, common_1.Param)('id')),
|
|
53
|
+
tslib_1.__metadata("design:type", Function),
|
|
54
|
+
tslib_1.__metadata("design:paramtypes", [Object, String]),
|
|
55
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
56
|
+
], NestController.prototype, "get", null);
|
|
57
|
+
tslib_1.__decorate([
|
|
58
|
+
(0, common_1.Post)(),
|
|
59
|
+
tslib_1.__param(0, (0, ModifyBody_decorator_1.ModifyBody)((0, ModifyBody_decorator_1.setCreatedBy)())),
|
|
60
|
+
tslib_1.__metadata("design:type", Function),
|
|
61
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
62
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
63
|
+
], NestController.prototype, "create", null);
|
|
64
|
+
tslib_1.__decorate([
|
|
65
|
+
(0, common_1.Patch)('/:id?'),
|
|
66
|
+
tslib_1.__param(0, (0, common_1.Query)()),
|
|
67
|
+
tslib_1.__param(1, (0, common_1.Body)()),
|
|
68
|
+
tslib_1.__param(2, (0, common_1.Param)('id')),
|
|
69
|
+
tslib_1.__metadata("design:type", Function),
|
|
70
|
+
tslib_1.__metadata("design:paramtypes", [Object, Object, String]),
|
|
71
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
72
|
+
], NestController.prototype, "patch", null);
|
|
73
|
+
tslib_1.__decorate([
|
|
74
|
+
(0, common_1.Delete)('/:id?'),
|
|
75
|
+
tslib_1.__param(0, (0, common_1.Param)('id')),
|
|
76
|
+
tslib_1.__param(1, (0, common_1.Query)()),
|
|
77
|
+
tslib_1.__param(2, (0, User_decorator_1.User)()),
|
|
78
|
+
tslib_1.__metadata("design:type", Function),
|
|
79
|
+
tslib_1.__metadata("design:paramtypes", [String, Object, Object]),
|
|
80
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
81
|
+
], NestController.prototype, "delete", null);
|
|
82
|
+
//# sourceMappingURL=nest.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nest.controller.js","sourceRoot":"","sources":["../../../../../packages/core/src/lib/nest.controller.ts"],"names":[],"mappings":";;;;AAAA,2CASwB;AACxB,4EAA+D;AAC/D,wEAA2D;AAE3D,oFAAqF;AAErF,MAAa,cAAc;IAGvB,YAA6B,OAA0B;QAA1B,YAAO,GAAP,OAAO,CAAmB;QAFpC,WAAM,GAAG,IAAI,eAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAED,CAAC;IAItD,IAAI,CAAU,KAA0B;;YAC1C,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3C,CAAC;KAAA;IAGK,GAAG,CAAU,KAA0B,EAAe,EAAU;;YAClE,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QAC9C,CAAC;KAAA;IAGK,MAAM,CAA6B,SAAY;;YACjD,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACjD,CAAC;KAAA;IAGK,KAAK,CACE,KAA0B,EAC3B,QAAoB,EACf,EAAU;;YAEvB,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC1D,CAAC;KAAA;IAGK,MAAM,CACK,EAAU,EACd,KAA0B,EAC3B,IAAS;;YAEjB,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QACvD,CAAC;KAAA;CACJ;AAtCD,wCAsCC;AA/BS;IAFL,IAAA,yBAAM,GAAE;IACR,IAAA,YAAG,GAAE;IACM,mBAAA,IAAA,cAAK,GAAE,CAAA;;;;0CAElB;AAGK;IADL,IAAA,YAAG,EAAC,OAAO,CAAC;IACF,mBAAA,IAAA,cAAK,GAAE,CAAA;IAA8B,mBAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;;;;yCAE1D;AAGK;IADL,IAAA,aAAI,GAAE;IACO,mBAAA,IAAA,iCAAU,EAAC,IAAA,mCAAY,GAAE,CAAC,CAAA;;;;4CAEvC;AAGK;IADL,IAAA,cAAK,EAAC,OAAO,CAAC;IAEV,mBAAA,IAAA,cAAK,GAAE,CAAA;IACP,mBAAA,IAAA,aAAI,GAAE,CAAA;IACN,mBAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;;;;2CAGf;AAGK;IADL,IAAA,eAAM,EAAC,OAAO,CAAC;IAEX,mBAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;IACX,mBAAA,IAAA,cAAK,GAAE,CAAA;IACP,mBAAA,IAAA,qBAAI,GAAE,CAAA;;;;4CAGV"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PaginatedResponse.js","sourceRoot":"","sources":["../../../../../packages/core/src/types/PaginatedResponse.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface ServiceOptions<T> {
|
|
2
|
+
_find(query: Record<string, any>, findOptions?: any): Promise<any>;
|
|
3
|
+
_get(id: string, query: Record<string, any>, getOptions?: any): Promise<any>;
|
|
4
|
+
_create(data: Partial<T>, needsMulti?: boolean): Promise<any>;
|
|
5
|
+
_patch(id: string | null, data: Partial<T>, query: Record<string, any>, patchOptions?: any): Promise<any>;
|
|
6
|
+
_remove(id: string | null, query: Record<string, any>, removeOptions?: any): Promise<any>;
|
|
7
|
+
}
|
|
8
|
+
export type NestServiceOptions = Partial<{
|
|
9
|
+
multi: boolean;
|
|
10
|
+
softDelete: boolean;
|
|
11
|
+
pagination: boolean;
|
|
12
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServiceOptions.js","sourceRoot":"","sources":["../../../../../packages/core/src/types/ServiceOptions.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration interface for NestExtended module.
|
|
3
|
+
* This allows the application to configure soft delete behavior
|
|
4
|
+
* without coupling the core package to application-specific schemas.
|
|
5
|
+
*/
|
|
6
|
+
export interface SoftDeleteConfig {
|
|
7
|
+
/**
|
|
8
|
+
* Returns the query filter to exclude soft-deleted documents.
|
|
9
|
+
* Default: { deleted: { $ne: true } }
|
|
10
|
+
*/
|
|
11
|
+
getQuery: () => Record<string, any>;
|
|
12
|
+
/**
|
|
13
|
+
* Returns the data to set when soft deleting a document.
|
|
14
|
+
* Receives the current user object from the controller.
|
|
15
|
+
* @param user - The authenticated user object from token verification
|
|
16
|
+
*/
|
|
17
|
+
getData: (user: any) => Record<string, any>;
|
|
18
|
+
}
|
|
19
|
+
export interface NestExtendedConfig {
|
|
20
|
+
/**
|
|
21
|
+
* Soft delete configuration.
|
|
22
|
+
* If not provided, default soft delete behavior is used.
|
|
23
|
+
*/
|
|
24
|
+
softDelete?: SoftDeleteConfig;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Injection token for NestExtended configuration.
|
|
28
|
+
* Use this to inject the config in services.
|
|
29
|
+
*/
|
|
30
|
+
export declare const NEST_EXTENDED_CONFIG: unique symbol;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NEST_EXTENDED_CONFIG = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Injection token for NestExtended configuration.
|
|
6
|
+
* Use this to inject the config in services.
|
|
7
|
+
*/
|
|
8
|
+
exports.NEST_EXTENDED_CONFIG = Symbol('NEST_EXTENDED_CONFIG');
|
|
9
|
+
//# sourceMappingURL=nest-extended.config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nest-extended.config.js","sourceRoot":"","sources":["../../../../../packages/core/src/types/nest-extended.config.ts"],"names":[],"mappings":";;;AA4BA;;;GAGG;AACU,QAAA,oBAAoB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC"}
|