mongodb-dynamic-api 4.8.0 → 4.10.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 +21 -0
- package/README.md +1 -0
- package/package.json +2 -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/helpers/route-description.helper.js +2 -0
- package/src/helpers/route-description.helper.js.map +1 -1
- package/src/index.d.ts +2 -0
- package/src/index.js +2 -0
- package/src/index.js.map +1 -1
- 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-presence.interface.d.ts +22 -0
- package/src/interfaces/dynamic-api-presence.interface.js +6 -0
- package/src/interfaces/dynamic-api-presence.interface.js.map +1 -0
- package/src/interfaces/dynamic-api-route-type.type.d.ts +1 -1
- package/src/interfaces/index.d.ts +2 -0
- package/src/interfaces/index.js +2 -0
- package/src/interfaces/index.js.map +1 -1
- package/src/modules/presence/adapters/in-memory-presence.adapter.d.ts +10 -0
- package/src/modules/presence/adapters/in-memory-presence.adapter.js +64 -0
- package/src/modules/presence/adapters/in-memory-presence.adapter.js.map +1 -0
- package/src/modules/presence/adapters/redis-presence.adapter.d.ts +17 -0
- package/src/modules/presence/adapters/redis-presence.adapter.js +80 -0
- package/src/modules/presence/adapters/redis-presence.adapter.js.map +1 -0
- package/src/modules/presence/index.d.ts +5 -0
- package/src/modules/presence/index.js +22 -0
- package/src/modules/presence/index.js.map +1 -0
- package/src/modules/presence/presence.controller.d.ts +6 -0
- package/src/modules/presence/presence.controller.js +55 -0
- package/src/modules/presence/presence.controller.js.map +1 -0
- package/src/modules/presence/presence.gateway.d.ts +13 -0
- package/src/modules/presence/presence.gateway.js +79 -0
- package/src/modules/presence/presence.gateway.js.map +1 -0
- package/src/modules/presence/presence.module.d.ts +5 -0
- package/src/modules/presence/presence.module.js +50 -0
- package/src/modules/presence/presence.module.js.map +1 -0
- 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/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/presence.e2e-spec.d.ts +1 -0
- package/test/for-feature/presence.e2e-spec.js +169 -0
- package/test/for-feature/presence.e2e-spec.js.map +1 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,55 @@
|
|
|
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.PresenceController = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
18
|
+
const decorators_1 = require("../../decorators");
|
|
19
|
+
const interfaces_1 = require("../../interfaces");
|
|
20
|
+
let PresenceController = class PresenceController {
|
|
21
|
+
constructor(presenceAdapter) {
|
|
22
|
+
this.presenceAdapter = presenceAdapter;
|
|
23
|
+
}
|
|
24
|
+
async getOnlineUsers(room) {
|
|
25
|
+
const onlineUserIds = await this.presenceAdapter.getOnlineUserIds(room);
|
|
26
|
+
return { onlineUserIds };
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.PresenceController = PresenceController;
|
|
30
|
+
__decorate([
|
|
31
|
+
(0, decorators_1.Public)(),
|
|
32
|
+
(0, common_1.Get)(),
|
|
33
|
+
(0, swagger_1.ApiOperation)({ summary: 'Get online user IDs (optionally filtered by room)' }),
|
|
34
|
+
(0, swagger_1.ApiQuery)({ name: 'room', required: false, type: String }),
|
|
35
|
+
(0, swagger_1.ApiOkResponse)({
|
|
36
|
+
description: 'List of online user IDs.',
|
|
37
|
+
schema: {
|
|
38
|
+
type: 'object',
|
|
39
|
+
properties: {
|
|
40
|
+
onlineUserIds: { type: 'array', items: { type: 'string' } },
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
}),
|
|
44
|
+
__param(0, (0, common_1.Query)('room')),
|
|
45
|
+
__metadata("design:type", Function),
|
|
46
|
+
__metadata("design:paramtypes", [String]),
|
|
47
|
+
__metadata("design:returntype", Promise)
|
|
48
|
+
], PresenceController.prototype, "getOnlineUsers", null);
|
|
49
|
+
exports.PresenceController = PresenceController = __decorate([
|
|
50
|
+
(0, swagger_1.ApiTags)('Presence'),
|
|
51
|
+
(0, common_1.Controller)('presence'),
|
|
52
|
+
__param(0, (0, common_1.Inject)(interfaces_1.DYNAMIC_API_PRESENCE_ADAPTER)),
|
|
53
|
+
__metadata("design:paramtypes", [Object])
|
|
54
|
+
], PresenceController);
|
|
55
|
+
//# sourceMappingURL=presence.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presence.controller.js","sourceRoot":"","sources":["../../../../libs/dynamic-api/src/modules/presence/presence.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAgE;AAChE,6CAAiF;AACjF,iDAA0C;AAC1C,iDAI0B;AAgBnB,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAC7B,YAEmB,eAAgC;QAAhC,oBAAe,GAAf,eAAe,CAAiB;IAChD,CAAC;IAeE,AAAN,KAAK,CAAC,cAAc,CAAgB,IAAa;QAC/C,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACxE,OAAO,EAAE,aAAa,EAAE,CAAC;IAC3B,CAAC;CACF,CAAA;AAvBY,gDAAkB;AAmBvB;IAbL,IAAA,mBAAM,GAAE;IACR,IAAA,YAAG,GAAE;IACL,IAAA,sBAAY,EAAC,EAAE,OAAO,EAAE,mDAAmD,EAAE,CAAC;IAC9E,IAAA,kBAAQ,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IACzD,IAAA,uBAAa,EAAC;QACb,WAAW,EAAE,0BAA0B;QACvC,MAAM,EAAE;YACN,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,aAAa,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;aAC5D;SACF;KACF,CAAC;IACoB,WAAA,IAAA,cAAK,EAAC,MAAM,CAAC,CAAA;;;;wDAGlC;6BAtBU,kBAAkB;IAF9B,IAAA,iBAAO,EAAC,UAAU,CAAC;IACnB,IAAA,mBAAU,EAAC,UAAU,CAAC;IAGlB,WAAA,IAAA,eAAM,EAAC,yCAA4B,CAAC,CAAA;;GAF5B,kBAAkB,CAuB9B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Server } from 'socket.io';
|
|
2
|
+
import { ExtendedSocket, GatewayOptions, PresenceAdapter } from '../../interfaces';
|
|
3
|
+
import { MongoDBDynamicApiLogger } from '../../logger';
|
|
4
|
+
export declare function createPresenceGateway(options?: GatewayOptions): {
|
|
5
|
+
new (presenceAdapter: PresenceAdapter): {
|
|
6
|
+
readonly logger: MongoDBDynamicApiLogger;
|
|
7
|
+
server: Server;
|
|
8
|
+
readonly presenceAdapter: PresenceAdapter;
|
|
9
|
+
afterInit(server: Server): void;
|
|
10
|
+
onSocketConnection(server: Server, socket: ExtendedSocket): void;
|
|
11
|
+
onSocketDisconnect(server: Server, userId: string, socketId: string): void;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
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.createPresenceGateway = createPresenceGateway;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const websockets_1 = require("@nestjs/websockets");
|
|
18
|
+
const socket_io_1 = require("socket.io");
|
|
19
|
+
const helpers_1 = require("../../helpers");
|
|
20
|
+
const interfaces_1 = require("../../interfaces");
|
|
21
|
+
const logger_1 = require("../../logger");
|
|
22
|
+
function createPresenceGateway(options = {}) {
|
|
23
|
+
let PresenceGateway = class PresenceGateway {
|
|
24
|
+
constructor(presenceAdapter) {
|
|
25
|
+
this.presenceAdapter = presenceAdapter;
|
|
26
|
+
this.logger = new logger_1.MongoDBDynamicApiLogger('PresenceGateway');
|
|
27
|
+
}
|
|
28
|
+
afterInit(server) {
|
|
29
|
+
server.on('connection', (socket) => {
|
|
30
|
+
this.onSocketConnection(server, socket);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
onSocketConnection(server, socket) {
|
|
34
|
+
const userId = socket.user?.id;
|
|
35
|
+
if (!userId) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
this.presenceAdapter.setOnline(userId, socket.id).then(() => {
|
|
39
|
+
const payload = { userId };
|
|
40
|
+
server.emit('user:online', payload);
|
|
41
|
+
if (helpers_1.DynamicApiWsConfigStore.debug) {
|
|
42
|
+
this.logger.log(`[Presence] user:online – userId=${userId}, socketId=${socket.id}`);
|
|
43
|
+
}
|
|
44
|
+
socket.on('disconnect', () => {
|
|
45
|
+
this.onSocketDisconnect(server, userId, socket.id);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
onSocketDisconnect(server, userId, socketId) {
|
|
50
|
+
this.presenceAdapter
|
|
51
|
+
.setOffline(userId, socketId)
|
|
52
|
+
.then(() => this.presenceAdapter.getSocketCount(userId))
|
|
53
|
+
.then((count) => {
|
|
54
|
+
if (helpers_1.DynamicApiWsConfigStore.debug) {
|
|
55
|
+
this.logger.log(`[Presence] user:offline – userId=${userId}, socketId=${socketId}, remainingSockets=${count}`);
|
|
56
|
+
}
|
|
57
|
+
if (count === 0) {
|
|
58
|
+
const payload = { userId };
|
|
59
|
+
server.emit('user:offline', payload);
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
.catch((err) => {
|
|
63
|
+
const message = err instanceof Error ? err.message : JSON.stringify(err);
|
|
64
|
+
this.logger.error(`[Presence] disconnect handler error: ${message}`);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
__decorate([
|
|
69
|
+
(0, websockets_1.WebSocketServer)(),
|
|
70
|
+
__metadata("design:type", socket_io_1.Server)
|
|
71
|
+
], PresenceGateway.prototype, "server", void 0);
|
|
72
|
+
PresenceGateway = __decorate([
|
|
73
|
+
(0, websockets_1.WebSocketGateway)(options),
|
|
74
|
+
__param(0, (0, common_1.Inject)(interfaces_1.DYNAMIC_API_PRESENCE_ADAPTER)),
|
|
75
|
+
__metadata("design:paramtypes", [Object])
|
|
76
|
+
], PresenceGateway);
|
|
77
|
+
return PresenceGateway;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=presence.gateway.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presence.gateway.js","sourceRoot":"","sources":["../../../../libs/dynamic-api/src/modules/presence/presence.gateway.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AA4BA,sDAsEC;AAlGD,2CAAwC;AACxC,mDAAsF;AACtF,yCAA2C;AAC3C,2CAAwD;AACxD,iDAM0B;AAC1B,yCAAuD;AAiBvD,SAAgB,qBAAqB,CAAC,UAA0B,EAAE;IAChE,IACM,eAAe,GADrB,MACM,eAAe;QAMnB,YAE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cAAc,CAAC,MAAM,CAAC,CAAC;iBACvD,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;gBACd,IAAI,iCAAuB,CAAC,KAAK,EAAE,CAAC;oBAClC,IAAI,CAAC,MAAM,CAAC,GAAG,CACb,oCAAoC,MAAM,cAAc,QAAQ,sBAAsB,KAAK,EAAE,CAC9F,CAAC;gBACJ,CAAC;gBAED,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;oBAChB,MAAM,OAAO,GAAyB,EAAE,MAAM,EAAE,CAAC;oBACjD,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;gBACvC,CAAC;YACH,CAAC,CAAC;iBACD,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;gBACtB,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;gBACzE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wCAAwC,OAAO,EAAE,CAAC,CAAC;YACvE,CAAC,CAAC,CAAC;QACP,CAAC;KACF,CAAA;IA7DC;QADC,IAAA,4BAAe,GAAE;kCACV,kBAAM;mDAAC;IAJX,eAAe;QADpB,IAAA,6BAAgB,EAAC,OAAO,CAAC;QAQrB,WAAA,IAAA,eAAM,EAAC,yCAA4B,CAAC,CAAA;;OAPnC,eAAe,CAiEpB;IAED,OAAO,eAAe,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
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 DynamicApiPresenceModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.DynamicApiPresenceModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const interfaces_1 = require("../../interfaces");
|
|
13
|
+
const dynamic_api_module_1 = require("../../dynamic-api.module");
|
|
14
|
+
const in_memory_presence_adapter_1 = require("./adapters/in-memory-presence.adapter");
|
|
15
|
+
const redis_presence_adapter_1 = require("./adapters/redis-presence.adapter");
|
|
16
|
+
const presence_controller_1 = require("./presence.controller");
|
|
17
|
+
const presence_gateway_1 = require("./presence.gateway");
|
|
18
|
+
let DynamicApiPresenceModule = DynamicApiPresenceModule_1 = class DynamicApiPresenceModule {
|
|
19
|
+
static register(options) {
|
|
20
|
+
const { adapter, redisUrl, redisTtlSeconds, enableController = false, } = options;
|
|
21
|
+
if (adapter === 'redis' && !redisUrl) {
|
|
22
|
+
throw new Error('DynamicApiPresenceModule: `redisUrl` is required when adapter is "redis".');
|
|
23
|
+
}
|
|
24
|
+
const adapterInstance = adapter === 'redis'
|
|
25
|
+
? new redis_presence_adapter_1.RedisPresenceAdapter(redisUrl, redisTtlSeconds)
|
|
26
|
+
: new in_memory_presence_adapter_1.InMemoryPresenceAdapter();
|
|
27
|
+
const adapterProvider = {
|
|
28
|
+
provide: interfaces_1.DYNAMIC_API_PRESENCE_ADAPTER,
|
|
29
|
+
useValue: adapterInstance,
|
|
30
|
+
};
|
|
31
|
+
const gatewayOptions = dynamic_api_module_1.DynamicApiModule.state.get('gatewayOptions') ??
|
|
32
|
+
dynamic_api_module_1.DynamicApiModule.state.get('broadcastGatewayOptions') ??
|
|
33
|
+
{};
|
|
34
|
+
const GatewayClass = (0, presence_gateway_1.createPresenceGateway)(gatewayOptions);
|
|
35
|
+
return {
|
|
36
|
+
module: DynamicApiPresenceModule_1,
|
|
37
|
+
providers: [
|
|
38
|
+
adapterProvider,
|
|
39
|
+
{ provide: GatewayClass, useClass: GatewayClass },
|
|
40
|
+
],
|
|
41
|
+
controllers: enableController ? [presence_controller_1.PresenceController] : [],
|
|
42
|
+
exports: [interfaces_1.DYNAMIC_API_PRESENCE_ADAPTER],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.DynamicApiPresenceModule = DynamicApiPresenceModule;
|
|
47
|
+
exports.DynamicApiPresenceModule = DynamicApiPresenceModule = DynamicApiPresenceModule_1 = __decorate([
|
|
48
|
+
(0, common_1.Module)({})
|
|
49
|
+
], DynamicApiPresenceModule);
|
|
50
|
+
//# sourceMappingURL=presence.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presence.module.js","sourceRoot":"","sources":["../../../../libs/dynamic-api/src/modules/presence/presence.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuD;AACvD,iDAG0B;AAC1B,iEAA4D;AAC5D,sFAAgF;AAChF,8EAAyE;AACzE,+DAA2D;AAC3D,yDAA2D;AAwBpD,IAAM,wBAAwB,gCAA9B,MAAM,wBAAwB;IACnC,MAAM,CAAC,QAAQ,CAAC,OAAgC;QAC9C,MAAM,EACJ,OAAO,EACP,QAAQ,EACR,eAAe,EACf,gBAAgB,GAAG,KAAK,GACzB,GAAG,OAAO,CAAC;QAEZ,IAAI,OAAO,KAAK,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;YACrC,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAC;QACJ,CAAC;QAED,MAAM,eAAe,GACnB,OAAO,KAAK,OAAO;YACjB,CAAC,CAAC,IAAI,6CAAoB,CAAC,QAAS,EAAE,eAAe,CAAC;YACtD,CAAC,CAAC,IAAI,oDAAuB,EAAE,CAAC;QAEpC,MAAM,eAAe,GAAG;YACtB,OAAO,EAAE,yCAA4B;YACrC,QAAQ,EAAE,eAAe;SAC1B,CAAC;QAEF,MAAM,cAAc,GAClB,qCAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC;YAC5C,qCAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,yBAAyB,CAAC;YACrD,EAAE,CAAC;QAEL,MAAM,YAAY,GAAG,IAAA,wCAAqB,EAAC,cAAc,CAAC,CAAC;QAE3D,OAAO;YACL,MAAM,EAAE,0BAAwB;YAChC,SAAS,EAAE;gBACT,eAAe;gBACf,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE;aAClD;YACD,WAAW,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,wCAAkB,CAAC,CAAC,CAAC,CAAC,EAAE;YACzD,OAAO,EAAE,CAAC,yCAA4B,CAAC;SACxC,CAAC;IACJ,CAAC;CACF,CAAA;AA1CY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,wBAAwB,CA0CpC"}
|
|
@@ -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,kEAA2B;AAC3B,oEAA4B;AAC5B,0EAA+B;AA3PjC,2CAiBwB;AACxB,+CAA+C;AAC/C,6CAOyB;AACzB,uCAAiC;AACjC,iDAAyD;AACzD,iEAA4D;AAC5D,2CAKuB;AAQvB,yCAAuD;AAKvD,MAAM,yBAAyB,GAAmD;IAChF,GAAG,EAAE,YAAG;IACR,IAAI,EAAE,aAAI;IACV,KAAK,EAAE,cAAK;IACZ,GAAG,EAAE,YAAG;IACR,MAAM,EAAE,eAAM;CACf,CAAC;AAeF,SAAS,2BAA2B,CAOlC,MAAoB,EACpB,EAAE,eAAe,GAAG,EAAE,EAAE,GAAG,iBAAiB,EAAuC,EACnF,iBAA8E,EAC9E,iBAA0B,EAC1B,+BAAuD;IAEvD,MAAM,EACJ,IAAI,EAAE,SAAS,EACf,MAAM,EACN,OAAO,EACP,OAAO,EAAE,YAAY,EACrB,QAAQ,EACR,WAAW,EACX,MAAM,GAAG,EAAE,EACX,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EAAE,0BAA0B,EACjD,IAAI,GACL,GAAG,iBAAiB,CAAC;IAE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,QAAQ,EAAE,mBAAmB,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Type, ValidationPipeOptions } from '@nestjs/common';
|
|
2
|
+
import { CustomRouteConfig, DynamicApiControllerOptions, GatewayOptions } from '../../interfaces';
|
|
3
|
+
import { BaseEntity } from '../../models';
|
|
4
|
+
declare function createCustomRouteGateway<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, gatewayOptions?: GatewayOptions): Type;
|
|
5
|
+
declare function getCustomRouteGatewayName(entityName: string, routePath: string, apiTag?: string, version?: string): string;
|
|
6
|
+
export { createCustomRouteGateway, getCustomRouteGatewayName };
|
|
@@ -0,0 +1,98 @@
|
|
|
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.createCustomRouteGateway = createCustomRouteGateway;
|
|
16
|
+
exports.getCustomRouteGatewayName = getCustomRouteGatewayName;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const jwt_1 = require("@nestjs/jwt");
|
|
19
|
+
const mongoose_1 = require("@nestjs/mongoose");
|
|
20
|
+
const websockets_1 = require("@nestjs/websockets");
|
|
21
|
+
const mongoose_2 = require("mongoose");
|
|
22
|
+
const decorators_1 = require("../../decorators");
|
|
23
|
+
const filters_1 = require("../../filters");
|
|
24
|
+
const gateways_1 = require("../../gateways");
|
|
25
|
+
const guards_1 = require("../../guards");
|
|
26
|
+
const helpers_1 = require("../../helpers");
|
|
27
|
+
const mixins_1 = require("../../mixins");
|
|
28
|
+
const dynamic_api_module_1 = require("../../dynamic-api.module");
|
|
29
|
+
function createCustomRouteGateway(entity, { useInterceptors = [], ...controllerOptions }, customRouteConfig, controllerVersion, controllerValidationPipeOptions, gatewayOptions = {}) {
|
|
30
|
+
const { path: routePath, handler, version: routeVersion, isPublic, guards = [], abilityPredicate, predicateBehavior, validationPipeOptions: routeValidationPipeOptions, eventName, dTOs, } = customRouteConfig;
|
|
31
|
+
const { apiTag } = controllerOptions;
|
|
32
|
+
const effectiveVersion = routeVersion ?? controllerVersion;
|
|
33
|
+
const effectiveValidationPipeOptions = routeValidationPipeOptions ?? controllerValidationPipeOptions;
|
|
34
|
+
const connectionName = dynamic_api_module_1.DynamicApiModule.state.get('connectionName');
|
|
35
|
+
const displayedName = (0, helpers_1.getDisplayedName)(apiTag, entity.name, undefined);
|
|
36
|
+
const routePathPascal = (0, helpers_1.pascalCase)(routePath) ?? 'Custom';
|
|
37
|
+
const uniqueDisplayedName = `${routePathPascal}${displayedName}`;
|
|
38
|
+
const event = eventName ?? (0, helpers_1.kebabCase)(`custom/${routePath}/${apiTag ?? entity.name}`);
|
|
39
|
+
const presenterType = dTOs?.presenter ?? entity;
|
|
40
|
+
const guardInstances = [
|
|
41
|
+
new guards_1.JwtSocketGuard(isPublic),
|
|
42
|
+
];
|
|
43
|
+
if (abilityPredicate) {
|
|
44
|
+
const PoliciesGuard = (0, mixins_1.SocketPoliciesGuardMixin)(entity, 'Custom', event, effectiveVersion, { abilityPredicate, isPublic, predicateBehavior });
|
|
45
|
+
guardInstances.push(PoliciesGuard);
|
|
46
|
+
}
|
|
47
|
+
guardInstances.push(...guards);
|
|
48
|
+
let CustomRouteGateway = class CustomRouteGateway extends gateways_1.BaseGateway {
|
|
49
|
+
constructor(model, jwtService) {
|
|
50
|
+
super(jwtService);
|
|
51
|
+
this.model = model;
|
|
52
|
+
this.jwtService = jwtService;
|
|
53
|
+
this.entity = entity;
|
|
54
|
+
}
|
|
55
|
+
async handle(socket, body) {
|
|
56
|
+
const result = await handler({
|
|
57
|
+
model: this.model,
|
|
58
|
+
user: socket?.user,
|
|
59
|
+
params: {},
|
|
60
|
+
body: body,
|
|
61
|
+
query: {},
|
|
62
|
+
});
|
|
63
|
+
const fromEntity = presenterType.fromEntity;
|
|
64
|
+
const data = fromEntity ? fromEntity(result) : result;
|
|
65
|
+
return { event, data };
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
__decorate([
|
|
69
|
+
(0, common_1.UseFilters)(new filters_1.DynamicAPIWsExceptionFilter()),
|
|
70
|
+
(0, common_1.UseGuards)(...guardInstances),
|
|
71
|
+
(0, websockets_1.SubscribeMessage)(event),
|
|
72
|
+
__param(0, (0, websockets_1.ConnectedSocket)()),
|
|
73
|
+
__param(1, (0, websockets_1.MessageBody)()),
|
|
74
|
+
__metadata("design:type", Function),
|
|
75
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
76
|
+
__metadata("design:returntype", Object)
|
|
77
|
+
], CustomRouteGateway.prototype, "handle", null);
|
|
78
|
+
CustomRouteGateway = __decorate([
|
|
79
|
+
(0, websockets_1.WebSocketGateway)(gatewayOptions),
|
|
80
|
+
(0, decorators_1.ValidatorPipe)(effectiveValidationPipeOptions),
|
|
81
|
+
(0, common_1.UseInterceptors)(common_1.ClassSerializerInterceptor, ...useInterceptors),
|
|
82
|
+
__param(0, (0, mongoose_1.InjectModel)(entity.name, connectionName)),
|
|
83
|
+
__param(1, (0, common_1.Optional)()),
|
|
84
|
+
__metadata("design:paramtypes", [mongoose_2.Model,
|
|
85
|
+
jwt_1.JwtService])
|
|
86
|
+
], CustomRouteGateway);
|
|
87
|
+
Object.defineProperty(CustomRouteGateway, 'name', {
|
|
88
|
+
value: `Custom${uniqueDisplayedName}${(0, helpers_1.addVersionSuffix)(effectiveVersion)}Gateway`,
|
|
89
|
+
writable: false,
|
|
90
|
+
});
|
|
91
|
+
return CustomRouteGateway;
|
|
92
|
+
}
|
|
93
|
+
function getCustomRouteGatewayName(entityName, routePath, apiTag, version) {
|
|
94
|
+
const displayedName = (0, helpers_1.getDisplayedName)(apiTag, entityName, undefined);
|
|
95
|
+
const routePathPascal = (0, helpers_1.pascalCase)(routePath) ?? 'Custom';
|
|
96
|
+
return `Custom${routePathPascal}${displayedName}${(0, helpers_1.addVersionSuffix)(version)}Gateway`;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=create-custom-route-gateway.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-custom-route-gateway.js","sourceRoot":"","sources":["../../../../libs/dynamic-api/src/routes/custom/create-custom-route-gateway.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAsKS,4DAAwB;AAAE,8DAAyB;AAtK5D,2CASwB;AACxB,qCAAyC;AACzC,+CAA+C;AAC/C,mDAK4B;AAC5B,uCAAiC;AACjC,iDAAiD;AACjD,2CAA4D;AAC5D,6CAA6C;AAC7C,yCAA8C;AAC9C,2CAA0F;AAS1F,yCAAwD;AAExD,iEAA4D;AAc5D,SAAS,wBAAwB,CAO/B,MAAoB,EACpB,EAAE,eAAe,GAAG,EAAE,EAAE,GAAG,iBAA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EAAC,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC,CAAA;QAExC,WAAA,IAAA,iBAAQ,GAAE,CAAA;yCADe,gBAAK;YACY,gBAAU;OANnD,kBAAkB,CA+BvB;IAED,MAAM,CAAC,cAAc,CAAC,kBAAkB,EAAE,MAAM,EAAE;QAChD,KAAK,EAAE,SAAS,mBAAmB,GAAG,IAAA,0BAAgB,EAAC,gBAAgB,CAAC,SAAS;QACjF,QAAQ,EAAE,KAAK;KAChB,CAAC,CAAC;IAEH,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAMD,SAAS,yBAAyB,CAChC,UAAkB,EAClB,SAAiB,EACjB,MAAe,EACf,OAAgB;IAEhB,MAAM,aAAa,GAAG,IAAA,0BAAgB,EAAC,MAAM,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;IACtE,MAAM,eAAe,GAAG,IAAA,oBAAU,EAAC,SAAS,CAAC,IAAI,QAAQ,CAAC;IAC1D,OAAO,SAAS,eAAe,GAAG,aAAa,GAAG,IAAA,0BAAgB,EAAC,OAAO,CAAC,SAAS,CAAC;AACvF,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./create-custom-route-controller"), exports);
|
|
18
|
+
__exportStar(require("./create-custom-route-gateway"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/dynamic-api/src/routes/custom/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mEAAiD;AACjD,gEAA8C"}
|
package/src/routes/index.d.ts
CHANGED
package/src/routes/index.js
CHANGED
|
@@ -18,6 +18,7 @@ __exportStar(require("./aggregate"), exports);
|
|
|
18
18
|
__exportStar(require("./cache-purge"), exports);
|
|
19
19
|
__exportStar(require("./create-many"), exports);
|
|
20
20
|
__exportStar(require("./create-one"), exports);
|
|
21
|
+
__exportStar(require("./custom"), exports);
|
|
21
22
|
__exportStar(require("./delete-many"), exports);
|
|
22
23
|
__exportStar(require("./delete-one"), exports);
|
|
23
24
|
__exportStar(require("./duplicate-many"), exports);
|
package/src/routes/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../libs/dynamic-api/src/routes/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,gDAA8B;AAC9B,gDAA8B;AAC9B,+CAA6B;AAC7B,gDAA8B;AAC9B,+CAA6B;AAC7B,mDAAiC;AACjC,kDAAgC;AAChC,6CAA2B;AAC3B,4CAA0B;AAC1B,gDAA8B;AAC9B,gDAA8B;AAC9B,+CAA6B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../libs/dynamic-api/src/routes/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,gDAA8B;AAC9B,gDAA8B;AAC9B,+CAA6B;AAC7B,2CAAyB;AACzB,gDAA8B;AAC9B,+CAA6B;AAC7B,mDAAiC;AACjC,kDAAgC;AAChC,6CAA2B;AAC3B,4CAA0B;AAC1B,gDAA8B;AAC9B,gDAA8B;AAC9B,+CAA6B"}
|
package/src/version.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'dotenv/config';
|