mongodb-dynamic-api 4.9.0 → 4.11.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 +26 -0
- package/package.json +1 -1
- package/src/dynamic-api.module.d.ts +1 -1
- package/src/dynamic-api.module.js +14 -1
- package/src/dynamic-api.module.js.map +1 -1
- package/src/gateways/base.gateway.d.ts +2 -2
- package/src/gateways/base.gateway.js +2 -3
- package/src/gateways/base.gateway.js.map +1 -1
- package/src/helpers/resolve-rooms.helper.d.ts +1 -1
- package/src/helpers/resolve-rooms.helper.js +2 -2
- package/src/helpers/resolve-rooms.helper.js.map +1 -1
- package/src/helpers/route-description.helper.js +2 -0
- package/src/helpers/route-description.helper.js.map +1 -1
- package/src/interfaces/dynamic-api-ability.interface.d.ts +1 -1
- package/src/interfaces/dynamic-api-broadcast-config.interface.d.ts +4 -4
- package/src/interfaces/dynamic-api-custom-route.interface.d.ts +34 -0
- package/src/interfaces/dynamic-api-custom-route.interface.js +3 -0
- package/src/interfaces/dynamic-api-custom-route.interface.js.map +1 -0
- package/src/interfaces/dynamic-api-options.interface.d.ts +2 -0
- package/src/interfaces/dynamic-api-options.interface.js.map +1 -1
- package/src/interfaces/dynamic-api-route-config.interface.d.ts +2 -2
- package/src/interfaces/dynamic-api-route-type.type.d.ts +1 -1
- package/src/interfaces/dynamic-api-service-before-save-callback.interface.d.ts +21 -21
- package/src/interfaces/index.d.ts +1 -0
- package/src/interfaces/index.js +1 -0
- package/src/interfaces/index.js.map +1 -1
- package/src/routes/custom/create-custom-route-controller.d.ts +7 -0
- package/src/routes/custom/create-custom-route-controller.js +133 -0
- package/src/routes/custom/create-custom-route-controller.js.map +1 -0
- package/src/routes/custom/create-custom-route-gateway.d.ts +6 -0
- package/src/routes/custom/create-custom-route-gateway.js +98 -0
- package/src/routes/custom/create-custom-route-gateway.js.map +1 -0
- package/src/routes/custom/index.d.ts +2 -0
- package/src/routes/custom/index.js +19 -0
- package/src/routes/custom/index.js.map +1 -0
- package/src/routes/index.d.ts +1 -0
- package/src/routes/index.js +1 -0
- package/src/routes/index.js.map +1 -1
- package/src/services/dynamic-api-broadcast/dynamic-api-broadcast.service.d.ts +2 -2
- package/src/services/dynamic-api-broadcast/dynamic-api-broadcast.service.js.map +1 -1
- package/src/version.json +1 -1
- package/test/for-feature/custom-routes.e2e-spec.d.ts +1 -0
- package/test/for-feature/custom-routes.e2e-spec.js +275 -0
- package/test/for-feature/custom-routes.e2e-spec.js.map +1 -0
- package/test/for-feature/room-broadcast.e2e-spec.js +37 -0
- package/test/for-feature/room-broadcast.e2e-spec.js.map +1 -1
- package/test/for-feature/websockets.e2e-spec.js.map +1 -1
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
Changelog
|
|
2
2
|
|
|
3
|
+
## [4.11.0](https://github.com/MikeDev75015/mongodb-dynamic-api/compare/v4.10.0...v4.11.0) (2026-05-25)
|
|
4
|
+
|
|
5
|
+
### callbacks
|
|
6
|
+
|
|
7
|
+
* **callbacks:** add BodyDTO generic to beforeSave context types ([4c04c50](https://github.com/MikeDev75015/mongodb-dynamic-api/commit/4c04c50f57e9b1e96d14f1eab83b45f76e2afd71))
|
|
8
|
+
|
|
9
|
+
### e2e
|
|
10
|
+
|
|
11
|
+
* **e2e:** cast user to UserEntity in websockets broadcast enabled predicate ([6ac68ef](https://github.com/MikeDev75015/mongodb-dynamic-api/commit/6ac68ef1a5f206d129ee6395a7afb55dc1714962))
|
|
12
|
+
|
|
13
|
+
### broadcast
|
|
14
|
+
|
|
15
|
+
* **broadcast:** pass socket.user to rooms callback ([da6177f](https://github.com/MikeDev75015/mongodb-dynamic-api/commit/da6177f307b3afb14e3b56bfef25c39d3ee9b514))
|
|
16
|
+
|
|
17
|
+
## [4.10.0](https://github.com/MikeDev75015/mongodb-dynamic-api/compare/v4.9.0...v4.10.0) (2026-05-25)
|
|
18
|
+
|
|
19
|
+
### custom-route
|
|
20
|
+
|
|
21
|
+
* **custom-route:** add WebSocket gateway support ([f7b54a4](https://github.com/MikeDev75015/mongodb-dynamic-api/commit/f7b54a4))
|
|
22
|
+
* **custom-route:** remove unnecessary type casts in controller factory ([8448e8e](https://github.com/MikeDev75015/mongodb-dynamic-api/commit/8448e8ee16c3ada8fdcb08c3d3252a05ca82b90a))
|
|
23
|
+
* **custom-route:** rename DynamicApiCustomRouteConfig to CustomRouteConfig ([4b67e6b](https://github.com/MikeDev75015/mongodb-dynamic-api/commit/4b67e6bffad70424d6898db3ffa47db0ac4e9a26))
|
|
24
|
+
|
|
25
|
+
### custom-routes
|
|
26
|
+
|
|
27
|
+
* **custom-routes:** add customRoutes option to forFeature() ([3a06adb](https://github.com/MikeDev75015/mongodb-dynamic-api/commit/3a06adb032102233d9a13bab35f05a7e7fbcb19e))
|
|
28
|
+
|
|
3
29
|
## [4.9.0](https://github.com/MikeDev75015/mongodb-dynamic-api/compare/v4.8.0...v4.9.0) (2026-05-25)
|
|
4
30
|
|
|
5
31
|
### presence
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ import { DynamicApiGlobalStateService } from './services';
|
|
|
5
5
|
export declare class DynamicApiModule {
|
|
6
6
|
static readonly state: DynamicApiGlobalStateService;
|
|
7
7
|
static forRoot<Entity extends BaseEntity = any>(uri: string, { useGlobalCache, cacheOptions, useAuth, routesConfig, webSocket, broadcastGatewayOptions, }?: DynamicApiForRootOptions<Entity>): DynamicModule;
|
|
8
|
-
static forFeature<Entity extends BaseEntity>({ entity, controllerOptions, routes, webSocket: featureWebSocket, extraImports, extraProviders, extraControllers, }: DynamicApiForFeatureOptions<Entity>): Promise<DynamicModule>;
|
|
8
|
+
static forFeature<Entity extends BaseEntity>({ entity, controllerOptions, routes, webSocket: featureWebSocket, extraImports, extraProviders, extraControllers, customRoutes, }: DynamicApiForFeatureOptions<Entity>): Promise<DynamicModule>;
|
|
9
9
|
private static buildStateFromOptions;
|
|
10
10
|
private static setDefaultRoutes;
|
|
11
11
|
}
|
|
@@ -52,7 +52,7 @@ let DynamicApiModule = DynamicApiModule_1 = class DynamicApiModule {
|
|
|
52
52
|
exports: [modules_1.DynamicApiConfigModule],
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
|
-
static forFeature({ entity, controllerOptions, routes, webSocket: featureWebSocket, extraImports, extraProviders, extraControllers, }) {
|
|
55
|
+
static forFeature({ entity, controllerOptions, routes, webSocket: featureWebSocket, extraImports, extraProviders, extraControllers, customRoutes = [], }) {
|
|
56
56
|
const schema = (0, helpers_1.buildSchemaFromEntity)(entity);
|
|
57
57
|
const databaseModule = mongoose_1.MongooseModule.forFeature([{ name: entity.name, schema }], this.state.get('connectionName'));
|
|
58
58
|
services_1.DynamicApiGlobalStateService.addEntitySchema(entity, schema);
|
|
@@ -68,6 +68,16 @@ let DynamicApiModule = DynamicApiModule_1 = class DynamicApiModule {
|
|
|
68
68
|
clearTimeout(waitForState);
|
|
69
69
|
}
|
|
70
70
|
const { version: controllerVersion, validationPipeOptions: controllerValidationPipeOptions, routesConfig: controllerRoutesConfig, } = controllerOptions;
|
|
71
|
+
const customRouteControllers = customRoutes.map((customRoute) => (0, routes_1.createCustomRouteController)(entity, controllerOptions, customRoute, controllerVersion, controllerValidationPipeOptions));
|
|
72
|
+
const customRouteGateways = customRoutes
|
|
73
|
+
.filter((cr) => cr.webSocket)
|
|
74
|
+
.map((customRoute) => {
|
|
75
|
+
const wsOptions = customRoute.webSocket
|
|
76
|
+
? (0, helpers_1.initializeConfigFromOptions)(customRoute.webSocket)
|
|
77
|
+
: DynamicApiModule_1.state.get('gatewayOptions') ?? null;
|
|
78
|
+
return (0, routes_1.createCustomRouteGateway)(entity, controllerOptions, customRoute, controllerVersion, controllerValidationPipeOptions, wsOptions ?? {});
|
|
79
|
+
});
|
|
80
|
+
const needsDatabaseModule = customRouteControllers.length > 0 || customRouteGateways.length > 0;
|
|
71
81
|
const castType = (t) => t;
|
|
72
82
|
const castModule = (m) => m;
|
|
73
83
|
const moduleByRouteType = new Map([
|
|
@@ -89,6 +99,7 @@ let DynamicApiModule = DynamicApiModule_1 = class DynamicApiModule {
|
|
|
89
99
|
const apiModule = {
|
|
90
100
|
module: DynamicApiModule_1,
|
|
91
101
|
imports: [
|
|
102
|
+
...(needsDatabaseModule ? [databaseModule] : []),
|
|
92
103
|
...routes.map((routeConfig) => {
|
|
93
104
|
const { type, description: routeDescription, version: routeVersion, validationPipeOptions: routeValidationPipeOptions, webSocket: routeWebSocket, } = routeConfig;
|
|
94
105
|
const module = moduleByRouteType.get(type);
|
|
@@ -104,6 +115,7 @@ let DynamicApiModule = DynamicApiModule_1 = class DynamicApiModule {
|
|
|
104
115
|
}),
|
|
105
116
|
],
|
|
106
117
|
controllers: [
|
|
118
|
+
...customRouteControllers,
|
|
107
119
|
...(isCacheEnabledForFeature
|
|
108
120
|
? [(0, routes_1.createCachePurgeController)(entity, controllerOptions)]
|
|
109
121
|
: []),
|
|
@@ -122,6 +134,7 @@ let DynamicApiModule = DynamicApiModule_1 = class DynamicApiModule {
|
|
|
122
134
|
?? this.state.get('gatewayOptions')
|
|
123
135
|
?? {}),
|
|
124
136
|
] : []),
|
|
137
|
+
...customRouteGateways,
|
|
125
138
|
],
|
|
126
139
|
};
|
|
127
140
|
resolve(apiModule);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-api.module.js","sourceRoot":"","sources":["../../libs/dynamic-api/src/dynamic-api.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,yDAAmE;AACnE,2CAAuD;AACvD,uCAAqE;AACrE,8EAAyE;AACzE,+CAAkD;AAElD,yCAA8D;AAC9D,qCAAkD;AAClD,uCAA2H;AAC3H,iDAA4D;AAC5D,6CAAuQ;AAEvQ,uCAAsF;AACtF,
|
|
1
|
+
{"version":3,"file":"dynamic-api.module.js","sourceRoot":"","sources":["../../libs/dynamic-api/src/dynamic-api.module.ts"],"names":[],"mappings":";;;;;;;;;;A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
3
3
|
import { BaseEntity } from '../models';
|
|
4
4
|
export declare abstract class BaseGateway<Entity extends BaseEntity> {
|
|
5
5
|
protected readonly jwtService: JwtService;
|
|
@@ -7,5 +7,5 @@ export declare abstract class BaseGateway<Entity extends BaseEntity> {
|
|
|
7
7
|
protected constructor(jwtService: JwtService);
|
|
8
8
|
protected addUserToSocket(socket: ExtendedSocket<Entity>, isPublic: boolean): void;
|
|
9
9
|
protected isValidManyBody<T extends object>(body: T): boolean;
|
|
10
|
-
protected broadcastIfNeeded<ResponseData extends object>(socket: ExtendedSocket, event: string, data: ResponseData[], broadcastConfig?:
|
|
10
|
+
protected broadcastIfNeeded<ResponseData extends object>(socket: ExtendedSocket, event: string, data: ResponseData[], broadcastConfig?: BroadcastConfig<ResponseData>): void;
|
|
11
11
|
}
|
|
@@ -4,7 +4,6 @@ exports.BaseGateway = void 0;
|
|
|
4
4
|
const websockets_1 = require("@nestjs/websockets");
|
|
5
5
|
const dynamic_api_module_1 = require("../dynamic-api.module");
|
|
6
6
|
const helpers_1 = require("../helpers");
|
|
7
|
-
const ws_config_store_1 = require("../helpers/ws-config.store");
|
|
8
7
|
const logger_1 = require("../logger");
|
|
9
8
|
class BaseGateway {
|
|
10
9
|
constructor(jwtService) {
|
|
@@ -57,8 +56,8 @@ class BaseGateway {
|
|
|
57
56
|
return;
|
|
58
57
|
}
|
|
59
58
|
const broadcastEvent = eventName || event;
|
|
60
|
-
const resolvedRooms = (0, helpers_1.resolveRooms)(rooms, broadcastData);
|
|
61
|
-
if (
|
|
59
|
+
const resolvedRooms = (0, helpers_1.resolveRooms)(rooms, broadcastData, socket.user);
|
|
60
|
+
if (helpers_1.DynamicApiWsConfigStore.debug) {
|
|
62
61
|
this.logger.log(`[WS] broadcastIfNeeded – event=${broadcastEvent}, rooms=${resolvedRooms ? JSON.stringify(resolvedRooms) : 'all'}, items=${broadcastData.length}`);
|
|
63
62
|
}
|
|
64
63
|
if (resolvedRooms) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.gateway.js","sourceRoot":"","sources":["../../../libs/dynamic-api/src/gateways/base.gateway.ts"],"names":[],"mappings":";;;AACA,mDAAiD;AAEjD,8DAAyD;AACzD,
|
|
1
|
+
{"version":3,"file":"base.gateway.js","sourceRoot":"","sources":["../../../libs/dynamic-api/src/gateways/base.gateway.ts"],"names":[],"mappings":";;;AACA,mDAAiD;AAEjD,8DAAyD;AACzD,wCAA4E;AAE5E,sCAAoD;AAIpD,MAAsB,WAAW;IAG/B,YAAyC,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;QAF9C,WAAM,GAAG,IAAI,gCAAuB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAEN,CAAC;IAEzD,eAAe,CAAC,MAA8B,EAAE,QAAiB;QACzE,MAAM,aAAa,GAAG,qCAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QAElE,IAAI,CAAC,aAAa,IAAI,QAAQ,EAAE,CAAC;YAC/B,OAAO;QACT,CAAC;QAED,MAAM,WAAW,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK;eAC5C,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,WAAW,CAAW,CAAC;QACpD,IAAI,QAAyD,CAAC;QAE9D,IAAI,WAAW,EAAE,CAAC;YAChB,IAAI,CAAC;gBACH,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,WAAW,EAAE;oBAC7C,MAAM,EAAE,qCAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC;iBAChD,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;gBACzC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;YACxC,CAAC;YAGD,MAAM,E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AA,sBAAY,EAAC,KAAK,EAAE,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QAEtE,IAAI,iCAAuB,CAAC,KAAK,EAAE,CAAC;YAClC,IAAI,CAAC,MAAM,CAAC,GAAG,CACb,kCAAkC,cAAc,WAC9C,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,KAClD,WAAW,aAAa,CAAC,MAAM,EAAE,CAClC,CAAC;QACJ,CAAC;QAED,IAAI,aAAa,EAAE,CAAC;YAClB,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;YACvB,GAAG,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;QAC5D,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;CACF;AA3FD,kCA2FC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { BroadcastRooms } from '../interfaces';
|
|
2
|
-
declare function resolveRooms<T extends object>(rooms: BroadcastRooms<T> | undefined, data: T[]): string[] | undefined;
|
|
2
|
+
declare function resolveRooms<T extends object, User = unknown>(rooms: BroadcastRooms<T, User> | undefined, data: T[], user?: User): string[] | undefined;
|
|
3
3
|
export { resolveRooms };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveRooms = resolveRooms;
|
|
4
|
-
function resolveRooms(rooms, data) {
|
|
4
|
+
function resolveRooms(rooms, data, user) {
|
|
5
5
|
if (!rooms) {
|
|
6
6
|
return undefined;
|
|
7
7
|
}
|
|
8
8
|
if (typeof rooms === 'function') {
|
|
9
9
|
const resolved = data.flatMap((item) => {
|
|
10
|
-
const result = rooms(item);
|
|
10
|
+
const result = rooms(item, user);
|
|
11
11
|
return Array.isArray(result) ? result : [result];
|
|
12
12
|
});
|
|
13
13
|
return [...new Set(resolved)];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-rooms.helper.js","sourceRoot":"","sources":["../../../libs/dynamic-api/src/helpers/resolve-rooms.helper.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"resolve-rooms.helper.js","sourceRoot":"","sources":["../../../libs/dynamic-api/src/helpers/resolve-rooms.helper.ts"],"names":[],"mappings":";;AAkCS,oCAAY;AArBrB,SAAS,YAAY,CACnB,KAA0C,EAC1C,IAAS,EACT,IAAW;IAEX,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACrC,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACjC,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;IAChC,CAAC;IAED,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAC3D,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -29,6 +29,8 @@ function getDefaultRouteDescription(routeType, entityName) {
|
|
|
29
29
|
return `Update one ${contentName}`;
|
|
30
30
|
case 'Aggregate':
|
|
31
31
|
return `Get aggregated ${contentName}`;
|
|
32
|
+
case 'Custom':
|
|
33
|
+
return `Custom ${contentName} endpoint`;
|
|
32
34
|
default:
|
|
33
35
|
throw new Error(`Route type "${routeType}" is not supported`);
|
|
34
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-description.helper.js","sourceRoot":"","sources":["../../../libs/dynamic-api/src/helpers/route-description.helper.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"route-description.helper.js","sourceRoot":"","sources":["../../../libs/dynamic-api/src/helpers/route-description.helper.ts"],"names":[],"mappings":";;AAuCS,gEAA0B;AAvCnC,mDAA4C;AAI5C,SAAS,0BAA0B,CAAC,SAAoB,EAAE,UAAkB;IAC1E,MAAM,WAAW,GAAG,IAAA,yBAAS,EAAC,UAAU,CAAC,CAAC;IAE1C,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,YAAY;YACf,OAAO,eAAe,WAAW,EAAE,CAAC;QACtC,KAAK,WAAW;YACd,OAAO,cAAc,WAAW,EAAE,CAAC;QACrC,KAAK,YAAY;YACf,OAAO,eAAe,WAAW,EAAE,CAAC;QACtC,KAAK,WAAW;YACd,OAAO,cAAc,WAAW,EAAE,CAAC;QACrC,KAAK,eAAe;YAClB,OAAO,kBAAkB,WAAW,EAAE,CAAC;QACzC,KAAK,cAAc;YACjB,OAAO,iBAAiB,WAAW,EAAE,CAAC;QACxC,KAAK,SAAS;YACZ,OAAO,YAAY,WAAW,EAAE,CAAC;QACnC,KAAK,QAAQ;YACX,OAAO,WAAW,WAAW,QAAQ,CAAC;QACxC,KAAK,YAAY;YACf,OAAO,eAAe,WAAW,EAAE,CAAC;QACtC,KAAK,YAAY;YACf,OAAO,eAAe,WAAW,EAAE,CAAC;QACtC,KAAK,WAAW;YACd,OAAO,cAAc,WAAW,EAAE,CAAC;QACrC,KAAK,WAAW;YACd,OAAO,kBAAkB,WAAW,EAAE,CAAC;QACzC,KAAK,QAAQ;YACX,OAAO,UAAU,WAAW,WAAW,CAAC;QAC1C;YACE,MAAM,IAAI,KAAK,CAAC,eAAe,SAAS,oBAAoB,CAAC,CAAC;IAClE,CAAC;AACH,CAAC"}
|
|
@@ -4,7 +4,7 @@ type PredicateBehavior = 'filter' | 'throw';
|
|
|
4
4
|
type AbilityPredicate<Entity extends BaseEntity, User = any> = (entity: Entity, user: User) => boolean;
|
|
5
5
|
type AuthAbilityPredicate<User = any, Body = unknown> = (user: User, body?: Body) => boolean;
|
|
6
6
|
type BroadcastAbilityPredicate<ResponseData extends object, User = any> = (data: ResponseData, user: User) => boolean;
|
|
7
|
-
type BroadcastRooms<T extends object> = string | string[] | ((data: T) => string | string[]);
|
|
7
|
+
type BroadcastRooms<T extends object, User = unknown> = string | string[] | ((data: T, user?: User) => string | string[]);
|
|
8
8
|
type ControllerAbilityPredicate<Entity extends BaseEntity> = {
|
|
9
9
|
targets: RouteType[];
|
|
10
10
|
predicate: AbilityPredicate<Entity>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BroadcastAbilityPredicate, BroadcastRooms } from './dynamic-api-ability.interface';
|
|
2
|
-
interface
|
|
3
|
-
enabled: boolean | BroadcastAbilityPredicate<ResponseData>;
|
|
2
|
+
interface BroadcastConfig<ResponseData extends object, User = unknown> {
|
|
3
|
+
enabled: boolean | BroadcastAbilityPredicate<ResponseData, User>;
|
|
4
4
|
eventName?: string;
|
|
5
|
-
rooms?: BroadcastRooms<ResponseData>;
|
|
5
|
+
rooms?: BroadcastRooms<ResponseData, User>;
|
|
6
6
|
}
|
|
7
|
-
export {
|
|
7
|
+
export { BroadcastConfig };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CanActivate, Type, ValidationPipeOptions } from '@nestjs/common';
|
|
2
|
+
import { Model } from 'mongoose';
|
|
3
|
+
import { BaseEntity } from '../models';
|
|
4
|
+
import { AbilityPredicate, PredicateBehavior } from './dynamic-api-ability.interface';
|
|
5
|
+
import { Mappable } from './dynamic-api-route-dtos-bundle.type';
|
|
6
|
+
import { DynamicApiWebSocketOptions } from './dynamic-api-web-socket.interface';
|
|
7
|
+
type HttpMethod = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
|
|
8
|
+
interface CustomRouteContext<Entity extends BaseEntity, Body = unknown, Query = unknown, Params extends Record<string, string> = Record<string, string>> {
|
|
9
|
+
model: Model<Entity>;
|
|
10
|
+
user: unknown;
|
|
11
|
+
params: Params;
|
|
12
|
+
body: Body;
|
|
13
|
+
query: Query;
|
|
14
|
+
}
|
|
15
|
+
interface CustomRouteConfig<Entity extends BaseEntity, Body = unknown, Query = unknown, Params extends Record<string, string> = Record<string, string>, Response = unknown> {
|
|
16
|
+
path: string;
|
|
17
|
+
method: HttpMethod;
|
|
18
|
+
handler: (ctx: CustomRouteContext<Entity, Body, Query, Params>) => Promise<Response>;
|
|
19
|
+
version?: string;
|
|
20
|
+
isPublic?: boolean;
|
|
21
|
+
description?: string;
|
|
22
|
+
guards?: Type<CanActivate>[];
|
|
23
|
+
abilityPredicate?: AbilityPredicate<Entity>;
|
|
24
|
+
predicateBehavior?: PredicateBehavior;
|
|
25
|
+
validationPipeOptions?: ValidationPipeOptions;
|
|
26
|
+
webSocket?: DynamicApiWebSocketOptions;
|
|
27
|
+
eventName?: string;
|
|
28
|
+
dTOs?: {
|
|
29
|
+
body?: Type;
|
|
30
|
+
query?: Type;
|
|
31
|
+
presenter?: Type & Partial<Mappable<Entity>>;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export type { HttpMethod, CustomRouteContext, CustomRouteConfig };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic-api-custom-route.interface.js","sourceRoot":"","sources":["../../../libs/dynamic-api/src/interfaces/dynamic-api-custom-route.interface.ts"],"names":[],"mappings":""}
|
|
@@ -4,6 +4,7 @@ import { BaseEntity } from '../models';
|
|
|
4
4
|
import { DynamicApiAuthOptions } from '../modules';
|
|
5
5
|
import { DynamicApiControllerOptions } from './dynamic-api-controller-options.interface';
|
|
6
6
|
import { DynamicApiCacheOptions } from './dynamic-api-cache-options.interface';
|
|
7
|
+
import { CustomRouteConfig } from './dynamic-api-custom-route.interface';
|
|
7
8
|
import { RoutesConfig } from './dynamic-api-global-state.interface';
|
|
8
9
|
import { DynamicAPIRouteConfig } from './dynamic-api-route-config.interface';
|
|
9
10
|
import { DynamicApiWebSocketOptions } from './dynamic-api-web-socket.interface';
|
|
@@ -24,5 +25,6 @@ interface DynamicApiForFeatureOptions<Entity extends BaseEntity> {
|
|
|
24
25
|
extraImports?: ModuleMetadata['imports'];
|
|
25
26
|
extraProviders?: ModuleMetadata['providers'];
|
|
26
27
|
extraControllers?: ModuleMetadata['controllers'];
|
|
28
|
+
customRoutes?: CustomRouteConfig<Entity>[];
|
|
27
29
|
}
|
|
28
30
|
export { DynamicApiForFeatureOptions, DynamicApiForRootOptions, DYNAMIC_API_GLOBAL_STATE };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-api-options.interface.js","sourceRoot":"","sources":["../../../libs/dynamic-api/src/interfaces/dynamic-api-options.interface.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"dynamic-api-options.interface.js","sourceRoot":"","sources":["../../../libs/dynamic-api/src/interfaces/dynamic-api-options.interface.ts"],"names":[],"mappings":";;;AAYA,MAAM,wBAAwB,GAAG,MAAM,CAAC,0BAA0B,CAAC,CAAC;AA2BJ,4DAAwB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NestInterceptor, Type, ValidationPipeOptions } from '@nestjs/common';
|
|
2
2
|
import { BaseEntity } from '../models';
|
|
3
3
|
import { AbilityPredicate, PredicateBehavior } from './dynamic-api-ability.interface';
|
|
4
|
-
import {
|
|
4
|
+
import { BroadcastConfig } from './dynamic-api-broadcast-config.interface';
|
|
5
5
|
import { CascadeConfig } from './dynamic-api-cascade-config.interface';
|
|
6
6
|
import { DTOsBundle } from './dynamic-api-route-dtos-bundle.type';
|
|
7
7
|
import { RouteType } from './dynamic-api-route-type.type';
|
|
@@ -26,7 +26,7 @@ interface DynamicApiRouteConfig<Entity extends BaseEntity> {
|
|
|
26
26
|
callback?: AfterSaveCallback<Entity>;
|
|
27
27
|
webSocket?: DynamicApiWebSocketOptions;
|
|
28
28
|
eventName?: string;
|
|
29
|
-
broadcast?:
|
|
29
|
+
broadcast?: BroadcastConfig<Entity>;
|
|
30
30
|
isArrayResponse?: boolean;
|
|
31
31
|
useInterceptors?: Type<NestInterceptor>[];
|
|
32
32
|
fromUser?: FromUserMap<Entity>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
type RouteType = 'CreateMany' | 'CreateOne' | 'DeleteMany' | 'DeleteOne' | 'DuplicateMany' | 'DuplicateOne' | 'GetMany' | 'GetOne' | 'ReplaceOne' | 'UpdateMany' | 'UpdateOne' | 'Aggregate';
|
|
1
|
+
type RouteType = 'CreateMany' | 'CreateOne' | 'DeleteMany' | 'DeleteOne' | 'DuplicateMany' | 'DuplicateOne' | 'GetMany' | 'GetOne' | 'ReplaceOne' | 'UpdateMany' | 'UpdateOne' | 'Aggregate' | 'Custom';
|
|
2
2
|
export { RouteType };
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { BaseEntity } from '../models';
|
|
2
2
|
import { CallbackMethods } from './dynamic-api-service-callback.interface';
|
|
3
|
-
type BeforeSaveCreateContext<Entity extends BaseEntity> = {
|
|
4
|
-
toCreate: Partial<
|
|
3
|
+
type BeforeSaveCreateContext<Entity extends BaseEntity, BodyDTO = Entity> = {
|
|
4
|
+
toCreate: Partial<BodyDTO>;
|
|
5
5
|
};
|
|
6
|
-
type BeforeSaveCreateManyContext<Entity extends BaseEntity> = {
|
|
7
|
-
toCreate: Partial<
|
|
6
|
+
type BeforeSaveCreateManyContext<Entity extends BaseEntity, BodyDTO = Entity> = {
|
|
7
|
+
toCreate: Partial<BodyDTO>[];
|
|
8
8
|
};
|
|
9
|
-
type BeforeSaveUpdateContext<Entity extends BaseEntity> = {
|
|
9
|
+
type BeforeSaveUpdateContext<Entity extends BaseEntity, BodyDTO = Entity> = {
|
|
10
10
|
id: string;
|
|
11
|
-
update: Partial<
|
|
11
|
+
update: Partial<BodyDTO>;
|
|
12
12
|
};
|
|
13
|
-
type BeforeSaveUpdateManyContext<Entity extends BaseEntity> = {
|
|
13
|
+
type BeforeSaveUpdateManyContext<Entity extends BaseEntity, BodyDTO = Entity> = {
|
|
14
14
|
ids: string[];
|
|
15
|
-
update: Partial<
|
|
15
|
+
update: Partial<BodyDTO>;
|
|
16
16
|
};
|
|
17
|
-
type BeforeSaveReplaceContext<Entity extends BaseEntity> = {
|
|
17
|
+
type BeforeSaveReplaceContext<Entity extends BaseEntity, BodyDTO = Entity> = {
|
|
18
18
|
id: string;
|
|
19
|
-
replacement: Partial<
|
|
19
|
+
replacement: Partial<BodyDTO>;
|
|
20
20
|
};
|
|
21
21
|
type BeforeSaveDeleteContext = {
|
|
22
22
|
id: string;
|
|
@@ -24,13 +24,13 @@ type BeforeSaveDeleteContext = {
|
|
|
24
24
|
type BeforeSaveDeleteManyContext = {
|
|
25
25
|
ids: string[];
|
|
26
26
|
};
|
|
27
|
-
type BeforeSaveDuplicateContext<Entity extends BaseEntity> = {
|
|
27
|
+
type BeforeSaveDuplicateContext<Entity extends BaseEntity, BodyDTO = Entity> = {
|
|
28
28
|
id: string;
|
|
29
|
-
override?: Partial<
|
|
29
|
+
override?: Partial<BodyDTO>;
|
|
30
30
|
};
|
|
31
|
-
type BeforeSaveDuplicateManyContext<Entity extends BaseEntity> = {
|
|
31
|
+
type BeforeSaveDuplicateManyContext<Entity extends BaseEntity, BodyDTO = Entity> = {
|
|
32
32
|
ids: string[];
|
|
33
|
-
override?: Partial<
|
|
33
|
+
override?: Partial<BodyDTO>;
|
|
34
34
|
};
|
|
35
35
|
type BeforeSaveCallback<Entity extends BaseEntity, Context = Record<string, unknown>, User = unknown> = (entity: Entity | undefined, context: Context, methods: CallbackMethods, user?: User) => Promise<Partial<Entity>>;
|
|
36
36
|
type BeforeSaveListCallback<Entity extends BaseEntity, Context = Record<string, unknown>, User = unknown> = (entities: Entity[] | undefined, context: Context, methods: CallbackMethods, user?: User) => Promise<Partial<Entity>[]>;
|
|
@@ -40,15 +40,15 @@ type AnyBeforeSaveCallback<Entity extends BaseEntity, User = unknown> = BeforeSa
|
|
|
40
40
|
type BeforeDeleteCallback<Entity extends BaseEntity, Context = Record<string, unknown>, User = unknown> = (entity: Entity | undefined, context: Context, methods: CallbackMethods, user?: User) => Promise<void>;
|
|
41
41
|
type BeforeDeleteManyCallback<Entity extends BaseEntity, Context = Record<string, unknown>, User = unknown> = (entities: Entity[], context: Context, methods: CallbackMethods, user?: User) => Promise<void>;
|
|
42
42
|
type AnyBeforeDeleteCallback<Entity extends BaseEntity, User = unknown> = BeforeDeleteCallback<Entity, BeforeSaveDeleteContext, User> | BeforeDeleteManyCallback<Entity, BeforeSaveDeleteManyContext, User>;
|
|
43
|
-
type DynamicApiServiceBeforeSaveCreateContext<Entity extends BaseEntity> = BeforeSaveCreateContext<Entity>;
|
|
44
|
-
type DynamicApiServiceBeforeSaveCreateManyContext<Entity extends BaseEntity> = BeforeSaveCreateManyContext<Entity>;
|
|
45
|
-
type DynamicApiServiceBeforeSaveUpdateContext<Entity extends BaseEntity> = BeforeSaveUpdateContext<Entity>;
|
|
46
|
-
type DynamicApiServiceBeforeSaveUpdateManyContext<Entity extends BaseEntity> = BeforeSaveUpdateManyContext<Entity>;
|
|
47
|
-
type DynamicApiServiceBeforeSaveReplaceContext<Entity extends BaseEntity> = BeforeSaveReplaceContext<Entity>;
|
|
43
|
+
type DynamicApiServiceBeforeSaveCreateContext<Entity extends BaseEntity, BodyDTO = Entity> = BeforeSaveCreateContext<Entity, BodyDTO>;
|
|
44
|
+
type DynamicApiServiceBeforeSaveCreateManyContext<Entity extends BaseEntity, BodyDTO = Entity> = BeforeSaveCreateManyContext<Entity, BodyDTO>;
|
|
45
|
+
type DynamicApiServiceBeforeSaveUpdateContext<Entity extends BaseEntity, BodyDTO = Entity> = BeforeSaveUpdateContext<Entity, BodyDTO>;
|
|
46
|
+
type DynamicApiServiceBeforeSaveUpdateManyContext<Entity extends BaseEntity, BodyDTO = Entity> = BeforeSaveUpdateManyContext<Entity, BodyDTO>;
|
|
47
|
+
type DynamicApiServiceBeforeSaveReplaceContext<Entity extends BaseEntity, BodyDTO = Entity> = BeforeSaveReplaceContext<Entity, BodyDTO>;
|
|
48
48
|
type DynamicApiServiceBeforeSaveDeleteContext = BeforeSaveDeleteContext;
|
|
49
49
|
type DynamicApiServiceBeforeSaveDeleteManyContext = BeforeSaveDeleteManyContext;
|
|
50
|
-
type DynamicApiServiceBeforeSaveDuplicateContext<Entity extends BaseEntity> = BeforeSaveDuplicateContext<Entity>;
|
|
51
|
-
type DynamicApiServiceBeforeSaveDuplicateManyContext<Entity extends BaseEntity> = BeforeSaveDuplicateManyContext<Entity>;
|
|
50
|
+
type DynamicApiServiceBeforeSaveDuplicateContext<Entity extends BaseEntity, BodyDTO = Entity> = BeforeSaveDuplicateContext<Entity, BodyDTO>;
|
|
51
|
+
type DynamicApiServiceBeforeSaveDuplicateManyContext<Entity extends BaseEntity, BodyDTO = Entity> = BeforeSaveDuplicateManyContext<Entity, BodyDTO>;
|
|
52
52
|
type DynamicApiServiceBeforeSaveCallback<Entity extends BaseEntity, Context = Record<string, unknown>, User = unknown> = BeforeSaveCallback<Entity, Context, User>;
|
|
53
53
|
type DynamicApiServiceBeforeSaveListCallback<Entity extends BaseEntity, Context = Record<string, unknown>, User = unknown> = BeforeSaveListCallback<Entity, Context, User>;
|
|
54
54
|
type DynamicApiServiceBeforeSaveDeleteCallback<Entity extends BaseEntity, Context = Record<string, unknown>, User = unknown> = BeforeSaveDeleteCallback<Entity, Context, User>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './dynamic-api-controller-options.interface';
|
|
2
|
+
export * from './dynamic-api-custom-route.interface';
|
|
2
3
|
export * from './dynamic-api-request.interface';
|
|
3
4
|
export * from './dynamic-api-decorator-builder.interface';
|
|
4
5
|
export * from './dynamic-api-cache-options.interface';
|
package/src/interfaces/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./dynamic-api-controller-options.interface"), exports);
|
|
18
|
+
__exportStar(require("./dynamic-api-custom-route.interface"), exports);
|
|
18
19
|
__exportStar(require("./dynamic-api-request.interface"), exports);
|
|
19
20
|
__exportStar(require("./dynamic-api-decorator-builder.interface"), exports);
|
|
20
21
|
__exportStar(require("./dynamic-api-cache-options.interface"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../libs/dynamic-api/src/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6EAA2D;AAC3D,kEAAgD;AAChD,4EAA0D;AAC1D,wEAAsD;AACtD,kEAAgD;AAChD,2EAAyD;AACzD,yEAAuD;AACvD,yEAAuD;AACvD,uEAAqD;AACrD,kEAAgD;AAChD,yEAAuD;AACvD,uEAAqD;AACrD,uEAAqD;AACrD,kEAAgD;AAChD,oEAAkD;AAClD,gEAA8C;AAC9C,yEAAuD;AACvD,uFAAqE;AACrE,2EAAyD;AACzD,2EAAyD;AACzD,qEAAmD;AACnD,qEAAmD;AACnD,mEAAiD"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../libs/dynamic-api/src/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6EAA2D;AAC3D,uEAAqD;AACrD,kEAAgD;AAChD,4EAA0D;AAC1D,wEAAsD;AACtD,kEAAgD;AAChD,2EAAyD;AACzD,yEAAuD;AACvD,yEAAuD;AACvD,uEAAqD;AACrD,kEAAgD;AAChD,yEAAuD;AACvD,uEAAqD;AACrD,uEAAqD;AACrD,kEAAgD;AAChD,oEAAkD;AAClD,gEAA8C;AAC9C,yEAAuD;AACvD,uFAAqE;AACrE,2EAAyD;AACzD,2EAAyD;AACzD,qEAAmD;AACnD,qEAAmD;AACnD,mEAAiD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Type, ValidationPipeOptions } from '@nestjs/common';
|
|
2
|
+
import { DynamicApiControllerOptions, CustomRouteConfig } from '../../interfaces';
|
|
3
|
+
import { BaseEntity } from '../../models';
|
|
4
|
+
declare function createCustomRouteController<Entity extends BaseEntity, Body = unknown, QueryDto = unknown, Params extends Record<string, string> = Record<string, string>, Response = unknown>(entity: Type<Entity>, { useInterceptors, ...controllerOptions }: DynamicApiControllerOptions<Entity>, customRouteConfig: CustomRouteConfig<Entity, Body, QueryDto, Params, Response>, controllerVersion?: string, controllerValidationPipeOptions?: ValidationPipeOptions): Type;
|
|
5
|
+
declare function getCustomRouteControllerName(entityName: string, routePath: string, apiTag?: string, version?: string): string;
|
|
6
|
+
declare function getCustomRoutePoliciesGuardName(entityName: string, routePath: string, apiTag?: string, version?: string): string;
|
|
7
|
+
export { createCustomRouteController, getCustomRouteControllerName, getCustomRoutePoliciesGuardName, };
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.createCustomRouteController = createCustomRouteController;
|
|
16
|
+
exports.getCustomRouteControllerName = getCustomRouteControllerName;
|
|
17
|
+
exports.getCustomRoutePoliciesGuardName = getCustomRoutePoliciesGuardName;
|
|
18
|
+
const common_1 = require("@nestjs/common");
|
|
19
|
+
const mongoose_1 = require("@nestjs/mongoose");
|
|
20
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
21
|
+
const mongoose_2 = require("mongoose");
|
|
22
|
+
const decorators_1 = require("../../decorators");
|
|
23
|
+
const dynamic_api_module_1 = require("../../dynamic-api.module");
|
|
24
|
+
const helpers_1 = require("../../helpers");
|
|
25
|
+
const mixins_1 = require("../../mixins");
|
|
26
|
+
const HTTP_METHOD_DECORATOR_MAP = {
|
|
27
|
+
GET: common_1.Get,
|
|
28
|
+
POST: common_1.Post,
|
|
29
|
+
PATCH: common_1.Patch,
|
|
30
|
+
PUT: common_1.Put,
|
|
31
|
+
DELETE: common_1.Delete,
|
|
32
|
+
};
|
|
33
|
+
function createCustomRouteController(entity, { useInterceptors = [], ...controllerOptions }, customRouteConfig, controllerVersion, controllerValidationPipeOptions) {
|
|
34
|
+
const { path: routePath, method, handler, version: routeVersion, isPublic, description, guards = [], abilityPredicate, predicateBehavior, validationPipeOptions: routeValidationPipeOptions, dTOs, } = customRouteConfig;
|
|
35
|
+
const { path: controllerPath, apiTag } = controllerOptions;
|
|
36
|
+
const effectiveVersion = routeVersion ?? controllerVersion;
|
|
37
|
+
const effectiveValidationPipeOptions = routeValidationPipeOptions ?? controllerValidationPipeOptions;
|
|
38
|
+
const baseDisplayedName = (0, helpers_1.getDisplayedName)(apiTag, entity.name, undefined);
|
|
39
|
+
const routePathPascal = (0, helpers_1.pascalCase)(routePath) ?? 'Custom';
|
|
40
|
+
const uniqueDisplayedName = `${routePathPascal}${baseDisplayedName}`;
|
|
41
|
+
const isAuthEnabled = dynamic_api_module_1.DynamicApiModule.state.get('isAuthEnabled');
|
|
42
|
+
const connectionName = dynamic_api_module_1.DynamicApiModule.state.get('connectionName');
|
|
43
|
+
const allGuards = [];
|
|
44
|
+
if (abilityPredicate) {
|
|
45
|
+
const PoliciesGuard = (0, mixins_1.RoutePoliciesGuardMixin)(entity, 'Custom', uniqueDisplayedName, effectiveVersion, abilityPredicate, undefined, predicateBehavior);
|
|
46
|
+
allGuards.push(PoliciesGuard);
|
|
47
|
+
}
|
|
48
|
+
allGuards.push(...guards);
|
|
49
|
+
const presenterType = dTOs?.presenter ?? entity;
|
|
50
|
+
let CustomRouteController = class CustomRouteController {
|
|
51
|
+
constructor(model) {
|
|
52
|
+
this.model = model;
|
|
53
|
+
this.entity = entity;
|
|
54
|
+
}
|
|
55
|
+
async handle(params, body, query, req) {
|
|
56
|
+
const result = await handler({
|
|
57
|
+
model: this.model,
|
|
58
|
+
user: req?.user,
|
|
59
|
+
params: params,
|
|
60
|
+
body: body,
|
|
61
|
+
query: query,
|
|
62
|
+
});
|
|
63
|
+
const fromEntity = presenterType.fromEntity;
|
|
64
|
+
return fromEntity ? fromEntity(result) : result;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
__decorate([
|
|
68
|
+
__param(0, (0, common_1.Param)()),
|
|
69
|
+
__param(1, (0, common_1.Body)()),
|
|
70
|
+
__param(2, (0, common_1.Query)()),
|
|
71
|
+
__param(3, (0, common_1.Request)()),
|
|
72
|
+
__metadata("design:type", Function),
|
|
73
|
+
__metadata("design:paramtypes", [Object, Object, Object, Object]),
|
|
74
|
+
__metadata("design:returntype", Promise)
|
|
75
|
+
], CustomRouteController.prototype, "handle", null);
|
|
76
|
+
CustomRouteController = __decorate([
|
|
77
|
+
(0, common_1.Controller)({ path: controllerPath, version: effectiveVersion }),
|
|
78
|
+
(0, swagger_1.ApiTags)(apiTag ?? entity.name),
|
|
79
|
+
(0, decorators_1.ValidatorPipe)(effectiveValidationPipeOptions),
|
|
80
|
+
(0, common_1.UseInterceptors)(common_1.ClassSerializerInterceptor, ...useInterceptors),
|
|
81
|
+
__param(0, (0, mongoose_1.InjectModel)(entity.name, connectionName)),
|
|
82
|
+
__metadata("design:paramtypes", [mongoose_2.Model])
|
|
83
|
+
], CustomRouteController);
|
|
84
|
+
if (dTOs?.body ?? dTOs?.query) {
|
|
85
|
+
const paramTypes = [Object, Object, Object, Object];
|
|
86
|
+
if (dTOs?.body)
|
|
87
|
+
paramTypes[1] = dTOs.body;
|
|
88
|
+
if (dTOs?.query)
|
|
89
|
+
paramTypes[2] = dTOs.query;
|
|
90
|
+
Reflect.defineMetadata('design:paramtypes', paramTypes, CustomRouteController.prototype, 'handle');
|
|
91
|
+
}
|
|
92
|
+
const descriptor = Object.getOwnPropertyDescriptor(CustomRouteController.prototype, 'handle');
|
|
93
|
+
HTTP_METHOD_DECORATOR_MAP[method](routePath)(CustomRouteController.prototype, 'handle', descriptor);
|
|
94
|
+
(0, swagger_1.ApiOperation)({
|
|
95
|
+
operationId: `custom${routePathPascal}${baseDisplayedName}${effectiveVersion ? 'V' + effectiveVersion : ''}`,
|
|
96
|
+
summary: description ?? `${method} /${routePath} — custom endpoint for ${entity.name}`,
|
|
97
|
+
})(CustomRouteController.prototype, 'handle', descriptor);
|
|
98
|
+
(0, swagger_1.ApiResponse)({
|
|
99
|
+
type: presenterType,
|
|
100
|
+
})(CustomRouteController.prototype, 'handle', descriptor);
|
|
101
|
+
if (dTOs?.body) {
|
|
102
|
+
(0, swagger_1.ApiBody)({ type: dTOs.body })(CustomRouteController.prototype, 'handle', descriptor);
|
|
103
|
+
}
|
|
104
|
+
if (dTOs?.query) {
|
|
105
|
+
(0, swagger_1.ApiQuery)({ type: dTOs.query })(CustomRouteController.prototype, 'handle', descriptor);
|
|
106
|
+
}
|
|
107
|
+
if (allGuards.length > 0) {
|
|
108
|
+
(0, common_1.UseGuards)(...allGuards)(CustomRouteController.prototype, 'handle', descriptor);
|
|
109
|
+
}
|
|
110
|
+
if (isPublic) {
|
|
111
|
+
(0, decorators_1.Public)()(CustomRouteController.prototype, 'handle', descriptor);
|
|
112
|
+
}
|
|
113
|
+
else if (isAuthEnabled) {
|
|
114
|
+
(0, swagger_1.ApiBearerAuth)()(CustomRouteController.prototype, 'handle', descriptor);
|
|
115
|
+
}
|
|
116
|
+
Object.defineProperty(CustomRouteController, 'name', {
|
|
117
|
+
value: `Custom${uniqueDisplayedName}${(0, helpers_1.addVersionSuffix)(effectiveVersion)}Controller`,
|
|
118
|
+
writable: false,
|
|
119
|
+
});
|
|
120
|
+
return CustomRouteController;
|
|
121
|
+
}
|
|
122
|
+
function getCustomRouteControllerName(entityName, routePath, apiTag, version) {
|
|
123
|
+
const baseDisplayedName = (0, helpers_1.getDisplayedName)(apiTag, entityName, undefined);
|
|
124
|
+
const routePathPascal = (0, helpers_1.pascalCase)(routePath) ?? 'Custom';
|
|
125
|
+
return `Custom${routePathPascal}${baseDisplayedName}${(0, helpers_1.addVersionSuffix)(version)}Controller`;
|
|
126
|
+
}
|
|
127
|
+
function getCustomRoutePoliciesGuardName(entityName, routePath, apiTag, version) {
|
|
128
|
+
const baseDisplayedName = (0, helpers_1.getDisplayedName)(apiTag, entityName, undefined);
|
|
129
|
+
const routePathPascal = (0, helpers_1.pascalCase)(routePath) ?? 'Custom';
|
|
130
|
+
const uniqueDisplayedName = `${routePathPascal}${baseDisplayedName}`;
|
|
131
|
+
return (0, helpers_1.provideName)('Custom', uniqueDisplayedName, version, 'PoliciesGuard');
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=create-custom-route-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-custom-route-controller.js","sourceRoot":"","sources":["../../../../libs/dynamic-api/src/routes/custom/create-custom-route-controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAyPE,kEA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