@nest-extended/core 0.0.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 +34 -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/{dist → src}/common/options.d.ts +2 -2
- package/{dist → src}/common/options.js +2 -2
- package/src/common/options.js.map +1 -0
- package/src/index.d.ts +7 -0
- package/src/index.js +13 -0
- package/src/index.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 +80 -0
- package/src/lib/nest.controller.js.map +1 -0
- package/src/types/PaginatedResponse.d.ts +6 -0
- package/{dist/lib/core.js → src/types/PaginatedResponse.js} +1 -4
- 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/dist/common/nestify.d.ts +0 -3
- package/dist/common/nestify.d.ts.map +0 -1
- package/dist/common/nestify.js +0 -31
- package/dist/common/options.d.ts.map +0 -1
- package/dist/common/query.utils.d.ts +0 -14
- package/dist/common/query.utils.d.ts.map +0 -1
- package/dist/common/query.utils.js +0 -110
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -9
- package/dist/lib/core.d.ts +0 -2
- package/dist/lib/core.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,7 +1,37 @@
|
|
|
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**: Moved to `@nest-extended/decorators`.
|
|
9
|
+
- `@User()`
|
|
10
|
+
- `@Public()`
|
|
11
|
+
- `@ModifyBody()`
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### NestController
|
|
16
|
+
|
|
17
|
+
Extend `NestController` to automatically expose standard CRUD endpoints.
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { NestController } from '@nest-extended/core';
|
|
21
|
+
import { MyService } from './my.service';
|
|
22
|
+
|
|
23
|
+
@Controller('my-resource')
|
|
24
|
+
export class MyController extends NestController<MyResource> {
|
|
25
|
+
constructor(private readonly myService: MyService) {
|
|
26
|
+
super(myService);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Decorators
|
|
32
|
+
|
|
33
|
+
Decorators have been moved to their own package.
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { User, Public, ModifyBody, setCreatedBy } from '@nest-extended/decorators';
|
|
37
|
+
```
|
package/package.json
CHANGED
|
@@ -1,27 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nest-extended/core",
|
|
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,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"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Warning: Modify this properly!
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
declare const _default: {
|
|
5
5
|
deleteKey: string;
|
|
6
6
|
defaultPagination: boolean;
|
|
7
7
|
defaultLimit: number;
|
|
8
8
|
defaultSkip: number;
|
|
9
9
|
multi: boolean;
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
export default _default;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.options = void 0;
|
|
4
3
|
/**
|
|
5
4
|
* Warning: Modify this properly!
|
|
6
5
|
*/
|
|
7
|
-
exports.
|
|
6
|
+
exports.default = {
|
|
8
7
|
deleteKey: 'deleted',
|
|
9
8
|
defaultPagination: true,
|
|
10
9
|
defaultLimit: 20,
|
|
11
10
|
defaultSkip: 0,
|
|
12
11
|
multi: false,
|
|
13
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,7 @@
|
|
|
1
|
+
export * from './lib/nest.controller';
|
|
2
|
+
export * from './lib/nest-extended.module';
|
|
3
|
+
export { default as options } from './common/options';
|
|
4
|
+
export * from './common/cls.helper';
|
|
5
|
+
export * from './types/nest-extended.config';
|
|
6
|
+
export * from './types/PaginatedResponse';
|
|
7
|
+
export * from './types/ServiceOptions';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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/nest.controller"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./lib/nest-extended.module"), exports);
|
|
7
|
+
var options_1 = require("./common/options");
|
|
8
|
+
Object.defineProperty(exports, "options", { enumerable: true, get: function () { return options_1.default; } });
|
|
9
|
+
tslib_1.__exportStar(require("./common/cls.helper"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./types/nest-extended.config"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./types/PaginatedResponse"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./types/ServiceOptions"), exports);
|
|
13
|
+
//# 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,gEAAsC;AACtC,qEAA2C;AAC3C,4CAAsD;AAA7C,kGAAA,OAAO,OAAW;AAC3B,8DAAoC;AACpC,uEAA6C;AAC7C,oEAA0C;AAC1C,iEAAuC"}
|
|
@@ -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,80 @@
|
|
|
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 decorators_1 = require("@nest-extended/decorators");
|
|
7
|
+
class NestController {
|
|
8
|
+
constructor(service) {
|
|
9
|
+
this.service = service;
|
|
10
|
+
this.logger = new common_1.Logger(NestController.name);
|
|
11
|
+
}
|
|
12
|
+
find(query) {
|
|
13
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
return yield this.service._find(query);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
get(query, id) {
|
|
18
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
return yield this.service._get(id, query);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
create(createDto) {
|
|
23
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
return yield this.service._create(createDto);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
patch(query, patchDto, id) {
|
|
28
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
return yield this.service._patch(id, patchDto, query);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
delete(id, query, user) {
|
|
33
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
return yield this.service._remove(id, query, user);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.NestController = NestController;
|
|
39
|
+
tslib_1.__decorate([
|
|
40
|
+
(0, decorators_1.Public)(),
|
|
41
|
+
(0, common_1.Get)(),
|
|
42
|
+
tslib_1.__param(0, (0, common_1.Query)()),
|
|
43
|
+
tslib_1.__metadata("design:type", Function),
|
|
44
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
45
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
46
|
+
], NestController.prototype, "find", null);
|
|
47
|
+
tslib_1.__decorate([
|
|
48
|
+
(0, common_1.Get)('/:id'),
|
|
49
|
+
tslib_1.__param(0, (0, common_1.Query)()),
|
|
50
|
+
tslib_1.__param(1, (0, common_1.Param)('id')),
|
|
51
|
+
tslib_1.__metadata("design:type", Function),
|
|
52
|
+
tslib_1.__metadata("design:paramtypes", [Object, String]),
|
|
53
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
54
|
+
], NestController.prototype, "get", null);
|
|
55
|
+
tslib_1.__decorate([
|
|
56
|
+
(0, common_1.Post)(),
|
|
57
|
+
tslib_1.__param(0, (0, decorators_1.ModifyBody)((0, decorators_1.setCreatedBy)())),
|
|
58
|
+
tslib_1.__metadata("design:type", Function),
|
|
59
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
60
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
61
|
+
], NestController.prototype, "create", null);
|
|
62
|
+
tslib_1.__decorate([
|
|
63
|
+
(0, common_1.Patch)('/:id'),
|
|
64
|
+
tslib_1.__param(0, (0, common_1.Query)()),
|
|
65
|
+
tslib_1.__param(1, (0, common_1.Body)()),
|
|
66
|
+
tslib_1.__param(2, (0, common_1.Param)('id')),
|
|
67
|
+
tslib_1.__metadata("design:type", Function),
|
|
68
|
+
tslib_1.__metadata("design:paramtypes", [Object, Object, String]),
|
|
69
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
70
|
+
], NestController.prototype, "patch", null);
|
|
71
|
+
tslib_1.__decorate([
|
|
72
|
+
(0, common_1.Delete)('/:id'),
|
|
73
|
+
tslib_1.__param(0, (0, common_1.Param)('id')),
|
|
74
|
+
tslib_1.__param(1, (0, common_1.Query)()),
|
|
75
|
+
tslib_1.__param(2, (0, decorators_1.User)()),
|
|
76
|
+
tslib_1.__metadata("design:type", Function),
|
|
77
|
+
tslib_1.__metadata("design:paramtypes", [String, Object, Object]),
|
|
78
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
79
|
+
], NestController.prototype, "delete", null);
|
|
80
|
+
//# 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,0DAAmF;AAGnF,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,mBAAM,GAAE;IACR,IAAA,YAAG,GAAE;IACM,mBAAA,IAAA,cAAK,GAAE,CAAA;;;;0CAElB;AAGK;IADL,IAAA,YAAG,EAAC,MAAM,CAAC;IACD,mBAAA,IAAA,cAAK,GAAE,CAAA;IAA8B,mBAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;;;;yCAE1D;AAGK;IADL,IAAA,aAAI,GAAE;IACO,mBAAA,IAAA,uBAAU,EAAC,IAAA,yBAAY,GAAE,CAAC,CAAA;;;;4CAEvC;AAGK;IADL,IAAA,cAAK,EAAC,MAAM,CAAC;IAET,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,MAAM,CAAC;IAEV,mBAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;IACX,mBAAA,IAAA,cAAK,GAAE,CAAA;IACP,mBAAA,IAAA,iBAAI,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"}
|
package/dist/common/nestify.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { Document, Query } from 'mongoose';
|
|
2
|
-
export declare function nestify<T extends Document, Q extends Query<any, T, any> = Query<any, T, any>>(q: Q, filters: NestifyFilters, options: NestifyOptions, isSingleOperation?: boolean, isPaginationDisabled?: boolean): void;
|
|
3
|
-
//# sourceMappingURL=nestify.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nestify.d.ts","sourceRoot":"","sources":["../../src/common/nestify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAE3C,wBAAgB,OAAO,CACrB,CAAC,SAAS,QAAQ,EAClB,CAAC,SAAS,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,EAEjD,CAAC,EAAE,CAAC,EACJ,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,cAAc,EACvB,iBAAiB,CAAC,EAAE,OAAO,EAC3B,oBAAoB,CAAC,EAAE,OAAO,GAC7B,IAAI,CAmCN"}
|
package/dist/common/nestify.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.nestify = nestify;
|
|
4
|
-
function nestify(q, filters, options, isSingleOperation, isPaginationDisabled) {
|
|
5
|
-
if (Array.isArray(filters.$select)) {
|
|
6
|
-
const selectFields = filters.$select.reduce((res, key) => {
|
|
7
|
-
res[key] = 1;
|
|
8
|
-
return res;
|
|
9
|
-
}, {});
|
|
10
|
-
q.select(selectFields);
|
|
11
|
-
}
|
|
12
|
-
else if (typeof filters.$select === 'string' || typeof filters.$select === 'object') {
|
|
13
|
-
q.select(filters.$select);
|
|
14
|
-
}
|
|
15
|
-
if (filters.$populate && options.defaultPagination) {
|
|
16
|
-
q.populate(filters.$populate);
|
|
17
|
-
}
|
|
18
|
-
if (filters.$sort) {
|
|
19
|
-
q.sort(filters.$sort);
|
|
20
|
-
}
|
|
21
|
-
if (!isPaginationDisabled && !isSingleOperation) {
|
|
22
|
-
const limit = Number(filters.$limit) || options.defaultLimit;
|
|
23
|
-
if (limit > 0) {
|
|
24
|
-
q.limit(limit);
|
|
25
|
-
}
|
|
26
|
-
const skip = Number(filters.$skip) || options.defaultSkip;
|
|
27
|
-
if (skip > 0) {
|
|
28
|
-
q.skip(skip);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/common/options.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,OAAO;;;;;;CAMnB,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare const FILTERS: Record<string, (value: any, options?: any) => any>;
|
|
2
|
-
export declare function parse(number?: any): number | undefined;
|
|
3
|
-
export declare const rawQuery: (query: Record<string, any>) => Record<string, any>;
|
|
4
|
-
export declare const OPERATORS: string[];
|
|
5
|
-
export declare const filterQuery: (query: Record<string, any>, options?: {
|
|
6
|
-
filters?: Record<string, (value: any, options?: any) => any>;
|
|
7
|
-
operators?: string[];
|
|
8
|
-
}) => {
|
|
9
|
-
filters: Record<string, any>;
|
|
10
|
-
query: Record<string, any>;
|
|
11
|
-
};
|
|
12
|
-
export declare const assignFilters: (object: Record<string, any>, query: Record<string, any>, filters: Record<string, (value: any, options?: any) => any> | string[], options: any) => Record<string, any>;
|
|
13
|
-
export declare const cleanQuery: (query: any, operators: string[], filters: Record<string, any>) => any;
|
|
14
|
-
//# sourceMappingURL=query.utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"query.utils.d.ts","sourceRoot":"","sources":["../../src/common/query.utils.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,KAAK,GAAG,CAMtE,CAAC;AAEF,wBAAgB,KAAK,CAAC,MAAM,CAAC,EAAE,GAAG,GAAG,MAAM,GAAG,SAAS,CAKtD;AAWD,eAAO,MAAM,QAAQ,UAAW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAmBvE,CAAC;AAYF,eAAO,MAAM,SAAS,UAA8D,CAAC;AAErF,eAAO,MAAM,WAAW,UACb,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,YACjB;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,KAAK,GAAG,CAAC,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE;;WAOlF,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAOnC,CAAC;AAEF,eAAO,MAAM,aAAa,WACd,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,SACpB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,WACjB,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,KAAK,GAAG,CAAC,GAAG,MAAM,EAAE,WAC7D,GAAG,KACb,MAAM,CAAC,MAAM,EAAE,GAAG,CAgBpB,CAAC;AAEF,eAAO,MAAM,UAAU,UACZ,GAAG,aACC,MAAM,EAAE,WACV,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAC7B,GAcF,CAAC"}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cleanQuery = exports.assignFilters = exports.filterQuery = exports.OPERATORS = exports.rawQuery = exports.FILTERS = void 0;
|
|
4
|
-
exports.parse = parse;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const common_1 = require("@nestjs/common");
|
|
7
|
-
const mongoose_1 = require("mongoose");
|
|
8
|
-
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
9
|
-
exports.FILTERS = {
|
|
10
|
-
$sort: (value) => convertSort(value),
|
|
11
|
-
$limit: (value, options) => getLimit(parse(value), options.paginate),
|
|
12
|
-
$skip: (value) => parse(value),
|
|
13
|
-
$select: (value) => value,
|
|
14
|
-
$populate: (value) => value,
|
|
15
|
-
};
|
|
16
|
-
function parse(number) {
|
|
17
|
-
if (typeof number !== 'undefined') {
|
|
18
|
-
return Math.abs(parseInt(number, 10));
|
|
19
|
-
}
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
function getLimit(limit, paginate) {
|
|
23
|
-
if (paginate?.default) {
|
|
24
|
-
const lower = typeof limit === 'number' && !isNaN(limit) ? limit : paginate.default;
|
|
25
|
-
const upper = typeof paginate.max === 'number' ? paginate.max : Number.MAX_VALUE;
|
|
26
|
-
return Math.min(lower, upper);
|
|
27
|
-
}
|
|
28
|
-
return limit ?? 0;
|
|
29
|
-
}
|
|
30
|
-
const rawQuery = (query) => {
|
|
31
|
-
const rawQ = {};
|
|
32
|
-
for (const key in query) {
|
|
33
|
-
if (Object.prototype.hasOwnProperty.call(query, key)) {
|
|
34
|
-
if (key.startsWith('$')) {
|
|
35
|
-
const filterKey = key.slice(1);
|
|
36
|
-
if (filterKey === 'regex') {
|
|
37
|
-
const field = Object.keys(query[key])[0];
|
|
38
|
-
const regexPattern = query[key][field];
|
|
39
|
-
rawQ[field] = { $regex: new RegExp(regexPattern, 'i') };
|
|
40
|
-
}
|
|
41
|
-
else if (filterKey === 'or' && Array.isArray(query[key])) {
|
|
42
|
-
rawQ['$or'] = query[key].map((subQuery) => (0, exports.rawQuery)(subQuery));
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
rawQ[key] = mongoose_1.Types.ObjectId.isValid(String(query[key])) ? new mongoose_1.Types.ObjectId(query[key]) : query[key];
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return rawQ;
|
|
51
|
-
};
|
|
52
|
-
exports.rawQuery = rawQuery;
|
|
53
|
-
function convertSort(sort) {
|
|
54
|
-
if (typeof sort !== 'object' || Array.isArray(sort)) {
|
|
55
|
-
return sort;
|
|
56
|
-
}
|
|
57
|
-
return Object.keys(sort).reduce((result, key) => {
|
|
58
|
-
result[key] = typeof sort[key] === 'object' ? sort[key] : parseInt(sort[key], 10);
|
|
59
|
-
return result;
|
|
60
|
-
}, {});
|
|
61
|
-
}
|
|
62
|
-
exports.OPERATORS = ['$in', '$nin', '$lt', '$lte', '$gt', '$gte', '$ne', '$or'];
|
|
63
|
-
const filterQuery = (query, options = {}) => {
|
|
64
|
-
const additionalFilters = options.filters ?? {};
|
|
65
|
-
const additionalOperators = options.operators ?? [];
|
|
66
|
-
const result = {
|
|
67
|
-
filters: (0, exports.assignFilters)({}, query, exports.FILTERS, options),
|
|
68
|
-
query: {},
|
|
69
|
-
};
|
|
70
|
-
result.filters = (0, exports.assignFilters)(result.filters, query, additionalFilters, options);
|
|
71
|
-
result.query = (0, exports.cleanQuery)(query, [...exports.OPERATORS, ...additionalOperators], result.filters);
|
|
72
|
-
return result;
|
|
73
|
-
};
|
|
74
|
-
exports.filterQuery = filterQuery;
|
|
75
|
-
const assignFilters = (object, query, filters, options) => {
|
|
76
|
-
if (Array.isArray(filters)) {
|
|
77
|
-
filters.forEach((key) => {
|
|
78
|
-
if (query[key] !== undefined) {
|
|
79
|
-
object[key] = query[key];
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
Object.entries(filters).forEach(([key, converter]) => {
|
|
85
|
-
const converted = converter(query[key], options);
|
|
86
|
-
if (converted !== undefined) {
|
|
87
|
-
object[key] = converted;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
return object;
|
|
92
|
-
};
|
|
93
|
-
exports.assignFilters = assignFilters;
|
|
94
|
-
const cleanQuery = (query, operators, filters) => {
|
|
95
|
-
if (Array.isArray(query)) {
|
|
96
|
-
return query.map((value) => (0, exports.cleanQuery)(value, operators, filters));
|
|
97
|
-
}
|
|
98
|
-
else if (lodash_1.default.isPlainObject(query)) {
|
|
99
|
-
const result = {};
|
|
100
|
-
Object.entries(query).forEach(([key, value]) => {
|
|
101
|
-
if (key.startsWith('$') && filters[key] === undefined && !operators.includes(key)) {
|
|
102
|
-
throw new common_1.BadRequestException(`Invalid query parameter: ${key}`);
|
|
103
|
-
}
|
|
104
|
-
result[key] = (0, exports.cleanQuery)(value, operators, filters);
|
|
105
|
-
});
|
|
106
|
-
return result;
|
|
107
|
-
}
|
|
108
|
-
return query;
|
|
109
|
-
};
|
|
110
|
-
exports.cleanQuery = cleanQuery;
|
package/dist/index.d.ts
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC"}
|
package/dist/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./lib/core"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./common/nestify"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./common/options"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./common/query.utils"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./types/PaginatedResponse"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./types/ServiceOptions"), exports);
|
package/dist/lib/core.d.ts
DELETED
package/dist/lib/core.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/lib/core.ts"],"names":[],"mappings":"AAAA,wBAAgB,IAAI,IAAI,MAAM,CAE7B"}
|