@scpxl/nodejs-framework 1.0.49 → 1.0.56
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 +12 -7
- package/dist/api-requester/api-requester.js +1 -1
- package/dist/api-requester/api-requester.js.map +2 -2
- package/dist/api-requester/index.d.ts +1 -1
- package/dist/api-requester/index.d.ts.map +1 -1
- package/dist/api-requester/index.js.map +2 -2
- package/dist/application/base-application.d.ts +6 -5
- package/dist/application/base-application.d.ts.map +1 -1
- package/dist/application/base-application.interface.d.ts +2 -4
- package/dist/application/base-application.interface.d.ts.map +1 -1
- package/dist/application/base-application.js +23 -14
- package/dist/application/base-application.js.map +2 -2
- package/dist/application/command-application.d.ts.map +1 -1
- package/dist/application/command-application.js +2 -2
- package/dist/application/command-application.js.map +2 -2
- package/dist/application/index.d.ts +3 -3
- package/dist/application/index.d.ts.map +1 -1
- package/dist/application/index.js +4 -4
- package/dist/application/index.js.map +2 -2
- package/dist/application/web-application.d.ts +5 -5
- package/dist/application/web-application.d.ts.map +1 -1
- package/dist/application/web-application.js +6 -7
- package/dist/application/web-application.js.map +2 -2
- package/dist/application/worker-application.d.ts +2 -2
- package/dist/application/worker-application.d.ts.map +1 -1
- package/dist/application/worker-application.js +2 -2
- package/dist/application/worker-application.js.map +2 -2
- package/dist/auth/jwt.d.ts.map +1 -1
- package/dist/auth/jwt.js +2 -2
- package/dist/auth/jwt.js.map +2 -2
- package/dist/cache/manager.d.ts.map +1 -1
- package/dist/cache/manager.js.map +2 -2
- package/dist/cli/index.js +192 -7029
- package/dist/cli/index.js.map +4 -4
- package/dist/cluster/cluster-manager.d.ts.map +1 -1
- package/dist/cluster/cluster-manager.js +1 -1
- package/dist/cluster/cluster-manager.js.map +2 -2
- package/dist/command/command.d.ts +1 -1
- package/dist/command/command.d.ts.map +1 -1
- package/dist/command/command.js.map +2 -2
- package/dist/config/env.d.ts +1 -1
- package/dist/config/env.d.ts.map +1 -1
- package/dist/config/env.js.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +1 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +1 -1
- package/dist/config/schema.js.map +2 -2
- package/dist/database/dynamic-entity.js +9 -9
- package/dist/database/dynamic-entity.js.map +2 -2
- package/dist/database/index.d.ts +3 -3
- package/dist/database/index.d.ts.map +1 -1
- package/dist/database/index.js +5 -5
- package/dist/database/index.js.map +2 -2
- package/dist/database/instance.d.ts +3 -3
- package/dist/database/instance.js +3 -3
- package/dist/database/instance.js.map +1 -1
- package/dist/database/manager.d.ts +1 -0
- package/dist/database/manager.d.ts.map +1 -1
- package/dist/database/manager.js +16 -3
- package/dist/database/manager.js.map +2 -2
- package/dist/error/error-reporter.js +1 -1
- package/dist/error/error-reporter.js.map +2 -2
- package/dist/error/index.d.ts +2 -3
- package/dist/error/index.d.ts.map +1 -1
- package/dist/error/index.js +8 -9
- package/dist/error/index.js.map +2 -2
- package/dist/event/controller/base.d.ts +2 -2
- package/dist/event/controller/base.d.ts.map +1 -1
- package/dist/event/controller/base.js +2 -2
- package/dist/event/controller/base.js.map +2 -2
- package/dist/event/index.d.ts +3 -3
- package/dist/event/index.d.ts.map +1 -1
- package/dist/event/index.js +5 -5
- package/dist/event/index.js.map +2 -2
- package/dist/event/manager.d.ts.map +1 -1
- package/dist/event/manager.interface.d.ts +2 -3
- package/dist/event/manager.interface.d.ts.map +1 -1
- package/dist/event/manager.js.map +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +2 -2
- package/dist/lifecycle/index.d.ts +3 -3
- package/dist/lifecycle/index.d.ts.map +1 -1
- package/dist/lifecycle/index.js +1 -1
- package/dist/lifecycle/index.js.map +2 -2
- package/dist/lifecycle/lifecycle-manager.d.ts +6 -0
- package/dist/lifecycle/lifecycle-manager.d.ts.map +1 -1
- package/dist/lifecycle/lifecycle-manager.js +28 -0
- package/dist/lifecycle/lifecycle-manager.js.map +2 -2
- package/dist/logger/logger.d.ts +20 -1
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.js +68 -96
- package/dist/logger/logger.js.map +2 -2
- package/dist/performance/cache-performance.d.ts.map +1 -1
- package/dist/performance/cache-performance.js +1 -1
- package/dist/performance/cache-performance.js.map +2 -2
- package/dist/performance/database-performance.d.ts.map +1 -1
- package/dist/performance/database-performance.js +1 -1
- package/dist/performance/database-performance.js.map +2 -2
- package/dist/performance/index.d.ts +3 -3
- package/dist/performance/index.d.ts.map +1 -1
- package/dist/performance/index.js +3 -3
- package/dist/performance/index.js.map +1 -1
- package/dist/performance/performance-monitor.js +2 -2
- package/dist/performance/performance-monitor.js.map +2 -2
- package/dist/performance/performance-monitor.plugin.d.ts.map +1 -1
- package/dist/performance/performance-monitor.plugin.js +1 -1
- package/dist/performance/performance-monitor.plugin.js.map +2 -2
- package/dist/performance/queue-performance.d.ts.map +1 -1
- package/dist/performance/queue-performance.js +1 -1
- package/dist/performance/queue-performance.js.map +2 -2
- package/dist/performance/webserver-performance.d.ts.map +1 -1
- package/dist/performance/webserver-performance.js +1 -1
- package/dist/performance/webserver-performance.js.map +2 -2
- package/dist/performance/websocket-performance.d.ts.map +1 -1
- package/dist/performance/websocket-performance.js +1 -1
- package/dist/performance/websocket-performance.js.map +2 -2
- package/dist/queue/index.d.ts +2 -2
- package/dist/queue/index.d.ts.map +1 -1
- package/dist/queue/index.interface.d.ts +1 -1
- package/dist/queue/index.interface.d.ts.map +1 -1
- package/dist/queue/index.js.map +2 -2
- package/dist/queue/manager.d.ts +9 -2
- package/dist/queue/manager.d.ts.map +1 -1
- package/dist/queue/manager.js +44 -6
- package/dist/queue/manager.js.map +2 -2
- package/dist/queue/processor/base.d.ts +5 -5
- package/dist/queue/processor/base.d.ts.map +1 -1
- package/dist/queue/processor/base.js +2 -2
- package/dist/queue/processor/base.js.map +2 -2
- package/dist/queue/processor/processor.interface.d.ts +3 -3
- package/dist/queue/processor/processor.interface.d.ts.map +1 -1
- package/dist/queue/worker.d.ts +5 -0
- package/dist/queue/worker.d.ts.map +1 -1
- package/dist/queue/worker.interface.d.ts +1 -1
- package/dist/queue/worker.interface.d.ts.map +1 -1
- package/dist/queue/worker.js +9 -1
- package/dist/queue/worker.js.map +2 -2
- package/dist/redis/index.d.ts +1 -1
- package/dist/redis/index.d.ts.map +1 -1
- package/dist/redis/index.js +5 -4
- package/dist/redis/index.js.map +2 -2
- package/dist/redis/instance.js +1 -1
- package/dist/redis/instance.js.map +2 -2
- package/dist/redis/manager.d.ts +7 -1
- package/dist/redis/manager.d.ts.map +1 -1
- package/dist/redis/manager.js +20 -4
- package/dist/redis/manager.js.map +2 -2
- package/dist/request-context/index.d.ts +1 -1
- package/dist/request-context/index.d.ts.map +1 -1
- package/dist/request-context/index.js +5 -5
- package/dist/request-context/index.js.map +1 -1
- package/dist/schemas/entity-builder.d.ts +3 -3
- package/dist/schemas/entity-builder.d.ts.map +1 -1
- package/dist/schemas/entity-builder.js.map +1 -1
- package/dist/services/aws/s3.d.ts.map +1 -1
- package/dist/services/aws/s3.js +7 -10
- package/dist/services/aws/s3.js.map +2 -2
- package/dist/util/file.d.ts +13 -8
- package/dist/util/file.d.ts.map +1 -1
- package/dist/util/file.js +6 -28
- package/dist/util/file.js.map +2 -2
- package/dist/util/helper.js +2 -2
- package/dist/util/helper.js.map +2 -2
- package/dist/util/index.d.ts +2 -2
- package/dist/util/index.d.ts.map +1 -1
- package/dist/util/index.js +18 -18
- package/dist/util/index.js.map +2 -2
- package/dist/util/loader.js +3 -3
- package/dist/util/loader.js.map +2 -2
- package/dist/util/os.js +2 -2
- package/dist/util/os.js.map +2 -2
- package/dist/webserver/controller/auth-middleware.d.ts +1 -1
- package/dist/webserver/controller/auth-middleware.d.ts.map +1 -1
- package/dist/webserver/controller/auth-middleware.js +1 -1
- package/dist/webserver/controller/auth-middleware.js.map +2 -2
- package/dist/webserver/controller/base.d.ts +6 -6
- package/dist/webserver/controller/base.d.ts.map +1 -1
- package/dist/webserver/controller/base.interface.d.ts +1 -1
- package/dist/webserver/controller/base.interface.d.ts.map +1 -1
- package/dist/webserver/controller/base.js +4 -4
- package/dist/webserver/controller/base.js.map +2 -2
- package/dist/webserver/controller/entity.d.ts +4 -3
- package/dist/webserver/controller/entity.d.ts.map +1 -1
- package/dist/webserver/controller/entity.js +26 -17
- package/dist/webserver/controller/entity.js.map +2 -2
- package/dist/webserver/controller/example-auth.d.ts.map +1 -1
- package/dist/webserver/controller/example-auth.js +1 -1
- package/dist/webserver/controller/example-auth.js.map +2 -2
- package/dist/webserver/controller/health.d.ts.map +1 -1
- package/dist/webserver/controller/health.js +1 -1
- package/dist/webserver/controller/health.js.map +2 -2
- package/dist/webserver/define-action.d.ts +1 -1
- package/dist/webserver/define-action.d.ts.map +1 -1
- package/dist/webserver/define-action.js.map +1 -1
- package/dist/webserver/define-route.d.ts +1 -1
- package/dist/webserver/define-route.d.ts.map +1 -1
- package/dist/webserver/define-route.js.map +2 -2
- package/dist/webserver/index.d.ts +9 -9
- package/dist/webserver/index.d.ts.map +1 -1
- package/dist/webserver/index.js +14 -14
- package/dist/webserver/index.js.map +2 -2
- package/dist/webserver/webserver.d.ts +3 -3
- package/dist/webserver/webserver.d.ts.map +1 -1
- package/dist/webserver/webserver.interface.d.ts +5 -5
- package/dist/webserver/webserver.interface.d.ts.map +1 -1
- package/dist/webserver/webserver.interface.js.map +1 -1
- package/dist/webserver/webserver.js +9 -9
- package/dist/webserver/webserver.js.map +2 -2
- package/dist/websocket/controller/server/base.d.ts +2 -2
- package/dist/websocket/controller/server/base.js.map +1 -1
- package/dist/websocket/controllers/server/system.d.ts.map +1 -1
- package/dist/websocket/controllers/server/system.js +1 -1
- package/dist/websocket/controllers/server/system.js.map +2 -2
- package/dist/websocket/index.d.ts +9 -11
- package/dist/websocket/index.d.ts.map +1 -1
- package/dist/websocket/index.js +22 -22
- package/dist/websocket/index.js.map +2 -2
- package/dist/websocket/subscriber-middleware.d.ts.map +1 -1
- package/dist/websocket/subscriber-middleware.js.map +2 -2
- package/dist/websocket/subscriber-utils.d.ts.map +1 -1
- package/dist/websocket/subscriber-utils.js.map +2 -2
- package/dist/websocket/utils.d.ts.map +1 -1
- package/dist/websocket/utils.js +4 -2
- package/dist/websocket/utils.js.map +2 -2
- package/dist/websocket/websocket-auth.d.ts.map +1 -1
- package/dist/websocket/websocket-auth.js +3 -3
- package/dist/websocket/websocket-auth.js.map +2 -2
- package/dist/websocket/websocket-base.d.ts +2 -2
- package/dist/websocket/websocket-base.d.ts.map +1 -1
- package/dist/websocket/websocket-base.js +1 -1
- package/dist/websocket/websocket-base.js.map +2 -2
- package/dist/websocket/websocket-client-manager.d.ts +2 -0
- package/dist/websocket/websocket-client-manager.d.ts.map +1 -1
- package/dist/websocket/websocket-client-manager.js +11 -4
- package/dist/websocket/websocket-client-manager.js.map +2 -2
- package/dist/websocket/websocket-client.d.ts +10 -5
- package/dist/websocket/websocket-client.d.ts.map +1 -1
- package/dist/websocket/websocket-client.js +27 -5
- package/dist/websocket/websocket-client.js.map +2 -2
- package/dist/websocket/websocket-room-manager.js +1 -1
- package/dist/websocket/websocket-room-manager.js.map +1 -1
- package/dist/websocket/websocket-server.d.ts +7 -7
- package/dist/websocket/websocket-server.d.ts.map +1 -1
- package/dist/websocket/websocket-server.js +25 -20
- package/dist/websocket/websocket-server.js.map +2 -2
- package/dist/websocket/websocket-service.d.ts +2 -2
- package/dist/websocket/websocket-service.d.ts.map +1 -1
- package/dist/websocket/websocket-service.js +1 -1
- package/dist/websocket/websocket-service.js.map +2 -2
- package/dist/websocket/websocket.interface.d.ts +3 -5
- package/dist/websocket/websocket.interface.d.ts.map +1 -1
- package/dist/websocket/websocket.interface.js.map +2 -2
- package/package.json +68 -64
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-middleware.d.ts","sourceRoot":"","sources":["../../../src/webserver/controller/auth-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEnD,YAAY,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEnD,MAAM,WAAW,oBAAqB,SAAQ,cAAc;IAC1D,IAAI,EAAE,iBAAiB,CAAC;CACzB;AAED,MAAM,MAAM,yBAAyB,GAAG,CAAC,OAAO,EAAE,oBAAoB,EAAE,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAC9G,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE3F;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,yBAAyB,EAClC,mBAAmB,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,GACvG,YAAY,CAed;AAED;;;GAGG;AACH,wBAAgB,YAAY,
|
|
1
|
+
{"version":3,"file":"auth-middleware.d.ts","sourceRoot":"","sources":["../../../src/webserver/controller/auth-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEnD,YAAY,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEnD,MAAM,WAAW,oBAAqB,SAAQ,cAAc;IAC1D,IAAI,EAAE,iBAAiB,CAAC;CACzB;AAED,MAAM,MAAM,yBAAyB,GAAG,CAAC,OAAO,EAAE,oBAAoB,EAAE,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAC9G,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE3F;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,yBAAyB,EAClC,mBAAmB,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,GACvG,YAAY,CAed;AAED;;;GAGG;AACH,wBAAgB,YAAY,KAClB,SAAS,GAAG,EAAE,cAAc,MAAM,EAAE,YAAY,kBAAkB,wBAoB3E"}
|
|
@@ -12,7 +12,7 @@ function withAuth(handler, authenticateRequest) {
|
|
|
12
12
|
}
|
|
13
13
|
__name(withAuth, "withAuth");
|
|
14
14
|
function requiresAuth() {
|
|
15
|
-
return
|
|
15
|
+
return (_target, _propertyKey, descriptor) => {
|
|
16
16
|
const originalMethod = descriptor.value;
|
|
17
17
|
descriptor.value = async function(request, reply) {
|
|
18
18
|
const user = await this.authenticateRequest(request, reply);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/webserver/controller/auth-middleware.ts"],
|
|
4
|
-
"sourcesContent": ["import type { FastifyReply, FastifyRequest } from 'fastify';\nimport type { AuthenticatedUser } from './base.js';\n\nexport type { AuthenticatedUser } from './base.js';\n\nexport interface AuthenticatedRequest extends FastifyRequest {\n user: AuthenticatedUser;\n}\n\nexport type AuthenticatedRouteHandler = (request: AuthenticatedRequest, reply: FastifyReply) => Promise<void>;\nexport type RouteHandler = (request: FastifyRequest, reply: FastifyReply) => Promise<void>;\n\n/**\n * Higher-order function that wraps a route handler with authentication\n * @param handler The route handler that requires authentication\n * @param authenticateRequest The authentication method from the controller\n * @returns A new route handler with authentication built-in\n */\nexport function withAuth(\n handler: AuthenticatedRouteHandler,\n authenticateRequest: (request: FastifyRequest, reply: FastifyReply) => Promise<AuthenticatedUser | null>,\n): RouteHandler {\n return async (request: FastifyRequest, reply: FastifyReply): Promise<void> => {\n const user = await authenticateRequest(request, reply);\n\n if (!user) {\n // Authentication failed, response already sent by authenticateRequest\n return;\n }\n\n // Add user to request object\n (request as AuthenticatedRequest).user = user;\n\n // Call the original handler with the authenticated request\n return handler(request as AuthenticatedRequest, reply);\n };\n}\n\n/**\n * Method decorator for class-based controllers\n * Usage: @requiresAuth()\n */\nexport function requiresAuth() {\n return
|
|
5
|
-
"mappings": ";;AAkBO,SAAS,SACd,SACA,qBACc;AACd,SAAO,OAAO,SAAyB,UAAuC;AAC5E,UAAM,OAAO,MAAM,oBAAoB,SAAS,KAAK;AAErD,QAAI,CAAC,MAAM;AAET;AAAA,IACF;AAGA,IAAC,QAAiC,OAAO;AAGzC,WAAO,QAAQ,SAAiC,KAAK;AAAA,EACvD;AACF;AAlBgB;AAwBT,SAAS,eAAe;AAC7B,SAAO,
|
|
4
|
+
"sourcesContent": ["import type { FastifyReply, FastifyRequest } from 'fastify';\nimport type { AuthenticatedUser } from './base.js';\n\nexport type { AuthenticatedUser } from './base.js';\n\nexport interface AuthenticatedRequest extends FastifyRequest {\n user: AuthenticatedUser;\n}\n\nexport type AuthenticatedRouteHandler = (request: AuthenticatedRequest, reply: FastifyReply) => Promise<void>;\nexport type RouteHandler = (request: FastifyRequest, reply: FastifyReply) => Promise<void>;\n\n/**\n * Higher-order function that wraps a route handler with authentication\n * @param handler The route handler that requires authentication\n * @param authenticateRequest The authentication method from the controller\n * @returns A new route handler with authentication built-in\n */\nexport function withAuth(\n handler: AuthenticatedRouteHandler,\n authenticateRequest: (request: FastifyRequest, reply: FastifyReply) => Promise<AuthenticatedUser | null>,\n): RouteHandler {\n return async (request: FastifyRequest, reply: FastifyReply): Promise<void> => {\n const user = await authenticateRequest(request, reply);\n\n if (!user) {\n // Authentication failed, response already sent by authenticateRequest\n return;\n }\n\n // Add user to request object\n (request as AuthenticatedRequest).user = user;\n\n // Call the original handler with the authenticated request\n return handler(request as AuthenticatedRequest, reply);\n };\n}\n\n/**\n * Method decorator for class-based controllers\n * Usage: @requiresAuth()\n */\nexport function requiresAuth() {\n return (_target: any, _propertyKey: string, descriptor: PropertyDescriptor) => {\n const originalMethod = descriptor.value;\n\n descriptor.value = async function (this: any, request: FastifyRequest, reply: FastifyReply) {\n const user = await this.authenticateRequest(request, reply);\n\n if (!user) {\n // Authentication failed, response already sent by authenticateRequest\n return;\n }\n\n // Add user to request object\n (request as AuthenticatedRequest).user = user;\n\n // Call the original method with the authenticated request\n return originalMethod.call(this, request, reply);\n };\n\n return descriptor;\n };\n}\n"],
|
|
5
|
+
"mappings": ";;AAkBO,SAAS,SACd,SACA,qBACc;AACd,SAAO,OAAO,SAAyB,UAAuC;AAC5E,UAAM,OAAO,MAAM,oBAAoB,SAAS,KAAK;AAErD,QAAI,CAAC,MAAM;AAET;AAAA,IACF;AAGA,IAAC,QAAiC,OAAO;AAGzC,WAAO,QAAQ,SAAiC,KAAK;AAAA,EACvD;AACF;AAlBgB;AAwBT,SAAS,eAAe;AAC7B,SAAO,CAAC,SAAc,cAAsB,eAAmC;AAC7E,UAAM,iBAAiB,WAAW;AAElC,eAAW,QAAQ,eAA2B,SAAyB,OAAqB;AAC1F,YAAM,OAAO,MAAM,KAAK,oBAAoB,SAAS,KAAK;AAE1D,UAAI,CAAC,MAAM;AAET;AAAA,MACF;AAGA,MAAC,QAAiC,OAAO;AAGzC,aAAO,eAAe,KAAK,MAAM,SAAS,KAAK;AAAA,IACjD;AAEA,WAAO;AAAA,EACT;AACF;AArBgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { StatusCodes } from 'http-status-codes';
|
|
2
1
|
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
3
|
-
import
|
|
4
|
-
import type { RedisInstance } from '../../redis/index.js';
|
|
5
|
-
import type { QueueManager } from '../../queue/index.js';
|
|
6
|
-
import type { ApiError, ApiResponse, WebServerBaseControllerConstructorParams } from './base.interface.js';
|
|
2
|
+
import { StatusCodes } from 'http-status-codes';
|
|
7
3
|
import type { ApplicationConfig } from '../../application/base-application.interface.js';
|
|
4
|
+
import type { DatabaseInstance } from '../../database/index.js';
|
|
8
5
|
import type EventManager from '../../event/manager.js';
|
|
9
|
-
import type { WebServerOptions } from '../webserver.interface.js';
|
|
10
6
|
import type { LifecycleManager } from '../../lifecycle/lifecycle-manager.js';
|
|
7
|
+
import type { QueueManager } from '../../queue/index.js';
|
|
8
|
+
import type { RedisInstance } from '../../redis/index.js';
|
|
9
|
+
import type { WebServerOptions } from '../webserver.interface.js';
|
|
10
|
+
import type { ApiError, ApiResponse, WebServerBaseControllerConstructorParams } from './base.interface.js';
|
|
11
11
|
export interface AuthenticatedUser<TPayload = Record<string, unknown>> {
|
|
12
12
|
userId: number;
|
|
13
13
|
payload: TPayload;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/webserver/controller/base.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/webserver/controller/base.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iDAAiD,CAAC;AAEzF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,KAAK,YAAY,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAE7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,gBAAg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,IAAI,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;KAC/B;IAYD,SAAS,CAAC,oBAAoB,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,GAAE,MAA6B;IAW1F,SAAS,CAAC,iBAAiB,CAAC,EAC1B,KAAK,EACL,KAAK,EACL,UAAoC,EACpC,SAAS,GACV,EAAE;QACD,KAAK,EAAE,YAAY,CAAC;QACpB,KAAK,EAAE,OAAO,CAAC;QACf,UAAU,CAAC,EAAE,WAAW,CAAC;QACzB,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;KAC9B;IA4CD,OAAO,CAAC,YAAY;cAoBJ,mBAAmB,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;CAwErH"}
|
|
@@ -2,11 +2,11 @@ import type { FastifyRequest } from 'fastify';
|
|
|
2
2
|
import type { ApplicationConfig } from '../../application/base-application.interface.js';
|
|
3
3
|
import type { DatabaseInstance } from '../../database/index.js';
|
|
4
4
|
import type EventManager from '../../event/manager.js';
|
|
5
|
+
import type { LifecycleManager } from '../../lifecycle/lifecycle-manager.js';
|
|
5
6
|
import type { QueueManager } from '../../queue/index.js';
|
|
6
7
|
import type { RedisInstance } from '../../redis/index.js';
|
|
7
8
|
import type { RouteHandler, RouteHandlerContext, RouteSchemaDefinition, WebServerOptions } from '../webserver.interface.js';
|
|
8
9
|
import type WebServerBaseController from './base.js';
|
|
9
|
-
import type { LifecycleManager } from '../../lifecycle/lifecycle-manager.js';
|
|
10
10
|
export interface WebServerBaseControllerConstructorParams<TQueueManager extends QueueManager = QueueManager, TRedisInstance extends RedisInstance = RedisInstance, TEventManager extends EventManager = EventManager, TDatabaseInstance extends DatabaseInstance = DatabaseInstance> {
|
|
11
11
|
applicationConfig: ApplicationConfig;
|
|
12
12
|
webServerOptions: WebServerOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.interface.d.ts","sourceRoot":"","sources":["../../../src/webserver/controller/base.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iDAAiD,CAAC;AACzF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,YAAY,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,uBAAuB,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"base.interface.d.ts","sourceRoot":"","sources":["../../../src/webserver/controller/base.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iDAAiD,CAAC;AACzF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,YAAY,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,uBAAuB,MAAM,WAAW,CAAC;AAErD,MAAM,WAAW,wCAAwC,CACvD,aAAa,SA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ACF,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,KAAK,CAAC,EAAE,QAAQ,CAAC;CAClB;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,YAAY,GAAG,gBAAgB,GAAG,eAAe,GAAG,WAAW,GAAG,cAAc,GAAG,cAAc,CAAC;IACxG,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;CAC5B"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import cluster from "node:cluster";
|
|
3
4
|
import { StatusCodes } from "http-status-codes";
|
|
4
|
-
import { Logger } from "../../logger/index.js";
|
|
5
|
-
import cluster from "cluster";
|
|
6
5
|
import Jwt from "../../auth/jwt.js";
|
|
7
6
|
import { safeSerializeError } from "../../error/error-reporter.js";
|
|
7
|
+
import { Logger } from "../../logger/index.js";
|
|
8
8
|
class BaseController {
|
|
9
9
|
static {
|
|
10
10
|
__name(this, "BaseController");
|
|
@@ -68,7 +68,7 @@ class BaseController {
|
|
|
68
68
|
errorType
|
|
69
69
|
}) {
|
|
70
70
|
let publicErrorMessage;
|
|
71
|
-
let errorDetails
|
|
71
|
+
let errorDetails;
|
|
72
72
|
if (this.webServerOptions.errors?.verbose === true) {
|
|
73
73
|
if (error instanceof Error) {
|
|
74
74
|
publicErrorMessage = error.stack ?? error.message;
|
|
@@ -169,7 +169,7 @@ class BaseController {
|
|
|
169
169
|
});
|
|
170
170
|
return null;
|
|
171
171
|
}
|
|
172
|
-
const userId = parseInt(payload.sub);
|
|
172
|
+
const userId = parseInt(payload.sub, 10);
|
|
173
173
|
return {
|
|
174
174
|
userId,
|
|
175
175
|
payload
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/webserver/controller/base.ts"],
|
|
4
|
-
"sourcesContent": ["import
|
|
5
|
-
"mappings": ";;AAAA,
|
|
4
|
+
"sourcesContent": ["import cluster from 'node:cluster';\nimport type { FastifyReply, FastifyRequest } from 'fastify';\nimport { StatusCodes } from 'http-status-codes';\nimport type { ApplicationConfig } from '../../application/base-application.interface.js';\nimport Jwt from '../../auth/jwt.js';\nimport type { DatabaseInstance } from '../../database/index.js';\nimport { safeSerializeError } from '../../error/error-reporter.js';\nimport type EventManager from '../../event/manager.js';\nimport type { LifecycleManager } from '../../lifecycle/lifecycle-manager.js';\nimport { Logger } from '../../logger/index.js';\nimport type { QueueManager } from '../../queue/index.js';\nimport type { RedisInstance } from '../../redis/index.js';\nimport type { WebServerOptions } from '../webserver.interface.js';\nimport type { ApiError, ApiResponse, WebServerBaseControllerConstructorParams } from './base.interface.js';\n\nexport interface AuthenticatedUser<TPayload = Record<string, unknown>> {\n userId: number;\n payload: TPayload;\n}\n\nexport default abstract class BaseController<\n TQueueManager extends QueueManager = QueueManager,\n TRedisInstance extends RedisInstance = RedisInstance,\n TEventManager extends EventManager = EventManager,\n TDatabaseInstance extends DatabaseInstance = DatabaseInstance,\n> {\n protected workerId: number | undefined;\n\n protected applicationConfig: ApplicationConfig;\n protected webServerOptions: WebServerOptions;\n\n protected redisInstance: TRedisInstance;\n protected queueManager: TQueueManager;\n protected eventManager: TEventManager;\n protected databaseInstance: TDatabaseInstance;\n protected lifecycleManager: LifecycleManager;\n\n constructor({\n applicationConfig,\n webServerOptions,\n redisInstance,\n queueManager,\n eventManager,\n databaseInstance,\n lifecycleManager,\n }: WebServerBaseControllerConstructorParams<TQueueManager, TRedisInstance, TEventManager, TDatabaseInstance>) {\n this.workerId = cluster.worker?.id;\n\n this.applicationConfig = applicationConfig;\n this.webServerOptions = webServerOptions;\n\n this.redisInstance = redisInstance;\n this.queueManager = queueManager;\n this.eventManager = eventManager;\n this.databaseInstance = databaseInstance;\n this.lifecycleManager = lifecycleManager;\n }\n\n protected sendSuccessResponse<T = unknown>({\n reply,\n data,\n statusCode = StatusCodes.OK,\n meta,\n }: {\n reply: FastifyReply;\n data: T;\n statusCode?: StatusCodes;\n meta?: ApiResponse<T>['meta'];\n }) {\n const response: ApiResponse<T> = {\n data,\n meta: {\n timestamp: new Date().toISOString(),\n requestId: reply.request.id || 'unknown',\n ...meta,\n },\n };\n reply.status(statusCode).send(response);\n }\n\n protected sendNotFoundResponse(reply: FastifyReply, message: string = 'Resource not found') {\n const error: ApiError = {\n message,\n type: 'not_found',\n timestamp: new Date().toISOString(),\n requestId: reply.request.id || 'unknown',\n };\n const response: ApiResponse = { error };\n reply.status(StatusCodes.NOT_FOUND).send(response);\n }\n\n protected sendErrorResponse({\n reply,\n error,\n statusCode = StatusCodes.BAD_REQUEST,\n errorType,\n }: {\n reply: FastifyReply;\n error: unknown;\n statusCode?: StatusCodes;\n errorType?: ApiError['type'];\n }) {\n let publicErrorMessage: string;\n let errorDetails: Record<string, unknown> | undefined;\n\n if (this.webServerOptions.errors?.verbose === true) {\n if (error instanceof Error) {\n publicErrorMessage = error.stack ?? error.message;\n errorDetails = { stack: error.stack, name: error.name };\n } else {\n publicErrorMessage = safeSerializeError(error);\n }\n } else {\n if (process.env.NODE_ENV === 'production') {\n if (error instanceof Error) {\n publicErrorMessage = 'Something went wrong';\n } else if (typeof error === 'string') {\n publicErrorMessage = error;\n } else {\n publicErrorMessage = 'An unknown error occurred';\n }\n } else {\n if (error instanceof Error) {\n publicErrorMessage = error.stack ?? error.message;\n errorDetails = { stack: error.stack, name: error.name };\n } else {\n publicErrorMessage = safeSerializeError(error);\n }\n }\n }\n\n Logger.error({ error });\n\n const apiError: ApiError = {\n message: publicErrorMessage,\n type: errorType ?? this.getErrorType(statusCode),\n timestamp: new Date().toISOString(),\n requestId: reply.request.id || 'unknown',\n ...(errorDetails && { details: errorDetails }),\n };\n\n const response: ApiResponse = { error: apiError };\n reply.status(statusCode).send(response);\n }\n\n private getErrorType(statusCode: StatusCodes): ApiError['type'] {\n switch (statusCode) {\n case StatusCodes.UNAUTHORIZED:\n return 'authentication';\n case StatusCodes.FORBIDDEN:\n return 'authorization';\n case StatusCodes.NOT_FOUND:\n return 'not_found';\n case StatusCodes.BAD_REQUEST:\n case StatusCodes.UNPROCESSABLE_ENTITY:\n return 'validation';\n case StatusCodes.INTERNAL_SERVER_ERROR:\n case StatusCodes.BAD_GATEWAY:\n case StatusCodes.SERVICE_UNAVAILABLE:\n return 'server_error';\n default:\n return 'client_error';\n }\n }\n\n protected async authenticateRequest(request: FastifyRequest, reply: FastifyReply): Promise<AuthenticatedUser | null> {\n // Get JWT secret key from application config\n const jwtSecretKey = this.applicationConfig.auth?.jwtSecretKey;\n\n if (!jwtSecretKey) {\n this.sendErrorResponse({\n reply,\n error: 'Authentication not configured.',\n statusCode: StatusCodes.INTERNAL_SERVER_ERROR,\n errorType: 'server_error',\n });\n return null;\n }\n\n const authHeader = request.headers.authorization;\n\n if (!authHeader) {\n this.sendErrorResponse({\n reply,\n error: 'No token provided.',\n statusCode: StatusCodes.UNAUTHORIZED,\n errorType: 'authentication',\n });\n return null;\n }\n\n if (!authHeader.startsWith('Bearer ')) {\n this.sendErrorResponse({\n reply,\n error: 'Invalid token.',\n statusCode: StatusCodes.UNAUTHORIZED,\n errorType: 'authentication',\n });\n return null;\n }\n\n try {\n const importedJwtSecretKey = await Jwt.importJwtSecretKey({\n jwtSecretKey,\n });\n\n // Remove \"Bearer \" from token\n const jwtAccessToken = authHeader.substring(7);\n\n const { payload } = await Jwt.jwtVerify(jwtAccessToken, importedJwtSecretKey);\n\n if (!payload.sub) {\n this.sendErrorResponse({\n reply,\n error: 'Invalid token payload.',\n statusCode: StatusCodes.UNAUTHORIZED,\n errorType: 'authentication',\n });\n return null;\n }\n\n const userId = parseInt(payload.sub, 10);\n\n return {\n userId,\n payload,\n };\n } catch {\n this.sendErrorResponse({\n reply,\n error: 'Invalid or expired token.',\n statusCode: StatusCodes.UNAUTHORIZED,\n errorType: 'authentication',\n });\n return null;\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA,OAAO,aAAa;AAEpB,SAAS,mBAAmB;AAE5B,OAAO,SAAS;AAEhB,SAAS,0BAA0B;AAGnC,SAAS,cAAc;AAWvB,MAAO,eAKL;AAAA,EAzBF,OAyBE;AAAA;AAAA;AAAA,EACU;AAAA,EAEA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEV,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAA8G;AAC5G,SAAK,WAAW,QAAQ,QAAQ;AAEhC,SAAK,oBAAoB;AACzB,SAAK,mBAAmB;AAExB,SAAK,gBAAgB;AACrB,SAAK,eAAe;AACpB,SAAK,eAAe;AACpB,SAAK,mBAAmB;AACxB,SAAK,mBAAmB;AAAA,EAC1B;AAAA,EAEU,oBAAiC;AAAA,IACzC;AAAA,IACA;AAAA,IACA,aAAa,YAAY;AAAA,IACzB;AAAA,EACF,GAKG;AACD,UAAM,WAA2B;AAAA,MAC/B;AAAA,MACA,MAAM;AAAA,QACJ,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,QAClC,WAAW,MAAM,QAAQ,MAAM;AAAA,QAC/B,GAAG;AAAA,MACL;AAAA,IACF;AACA,UAAM,OAAO,UAAU,EAAE,KAAK,QAAQ;AAAA,EACxC;AAAA,EAEU,qBAAq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E,UAAI,CAAC,QAAQ,KAAK;AAChB,aAAK,kBAAkB;AAAA,UACrB;AAAA,UACA,OAAO;AAAA,UACP,YAAY,YAAY;AAAA,UACxB,WAAW;AAAA,QACb,CAAC;AACD,eAAO;AAAA,MACT;AAEA,YAAM,SAAS,SAAS,QAAQ,KAAK,EAAE;AAEvC,aAAO;AAAA,QACL;AAAA,QACA;AAAA,MACF;AAAA,IACF,QAAQ;AACN,WAAK,kBAAkB;AAAA,QACrB;AAAA,QACA,OAAO;AAAA,QACP,YAAY,YAAY;AAAA,QACxB,WAAW;AAAA,MACb,CAAC;AACD,aAAO;AAAA,IACT;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import type { EntityManager } from '@mikro-orm/core';
|
|
3
3
|
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
4
|
-
import BaseController from './base.js';
|
|
5
4
|
import type { DynamicEntity } from '../../database/dynamic-entity.js';
|
|
5
|
+
import BaseController from './base.js';
|
|
6
6
|
export default abstract class EntityController extends BaseController {
|
|
7
7
|
protected abstract entityName: string;
|
|
8
8
|
private static entityCache;
|
|
9
|
+
private static entityPropertiesCache;
|
|
9
10
|
/**
|
|
10
11
|
* Get request-scoped EntityManager with automatic cleanup
|
|
11
12
|
* Creates a new EM fork per request, cleaned up after response
|
|
@@ -15,8 +16,8 @@ export default abstract class EntityController extends BaseController {
|
|
|
15
16
|
private getRequestEntityManager;
|
|
16
17
|
protected getEntity: () => Promise<typeof DynamicEntity | undefined>;
|
|
17
18
|
private getEntityProperties;
|
|
18
|
-
options: (
|
|
19
|
-
metadata: (
|
|
19
|
+
options: (_request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
20
|
+
metadata: (_request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
20
21
|
protected preGetMany(_: {
|
|
21
22
|
entityManager: EntityManager;
|
|
22
23
|
request: FastifyRequest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../../src/webserver/controller/entity.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,aAAa,EAAyB,MAAM,iBAAiB,CAAC;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,
|
|
1
|
+
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../../src/webserver/controller/entity.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,aAAa,EAAyB,MAAM,iBAAiB,CAAC;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAGtE,OAAO,cAAc,MAAM,WAAW,CAAC;AAEvC,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,gBAAiB,SAAQ,cAAc;IACnE,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAGtC,OAAO,CAAC,MAAM,CAAC,WAAW,CAA2C;IAIrE,OAAO,CAAC,MAAM,CAAC,qBAAqB,CAAqC;IAEzE;;;;;OAKG;IACH,OAAO,CAAC,uBAAuB;IAO/B,SAAS,CAAC,SAAS,QAAa,OAAO,CAAC,OAAO,aAAa,GAAG,SAAS,CAAC,CA+BvE;IAEF,OAAO,CAAC,mBAAmB;IA4BpB,OAAO,GAAU,UAAU,cAAc,EAAE,OAAO,YAAY,mBAqBnE;IAEK,QAAQ,GAAU,UAAU,cAAc,EAAE,OAAO,YAAY,mBAqBpE;cAGc,UAAU,CAAC,CAAC,EAAE;QAC5B,aAAa,EAAE,aAAa,CAAC;QAC7B,OAAO,EAAE,cAAc,CAAC;QACxB,KAAK,EAAE,YAAY,CAAC;KACrB,G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B;IAEF,SAAS,CAAC,YAAY,GAAI,qBAGvB;QACD,OAAO,EAAE,cAAc,CAAC;QACxB,KAAK,EAAE,YAAY,CAAC;KACrB,KAAG;QAAE,OAAO,EAAE,cAAc,CAAC;QAAC,KAAK,EAAE,YAAY,CAAA;KAAE,CAElD;cAEc,aAAa,CAAC,CAAC,EAAE;QAC/B,aAAa,EAAE,aAAa,CAAC;QAC7B,OAAO,EAAE,cAAc,CAAC;QACxB,KAAK,EAAE,YAAY,CAAC;QACpB,IAAI,EAAE,GAAG,CAAC;KACX,GAAG,OAAO,CAAC,IAAI,CAAC;IAEV,SAAS,GAAU,SAAS,cAAc,EAAE,OAAO,YAAY,mBA6CpE;cAEc,aAAa,CAAC,CAAC,EAAE;QAC/B,aAAa,EAAE,aAAa,CAAC;QAC7B,OAAO,EAAE,cAAc,CAAC;QACxB,KAAK,EAAE,YAAY,CAAC;QACpB,IAAI,EAAE,GAAG,CAAC;KACX,GAAG,OAAO,CAAC,IAAI,CAAC;IAEV,SAAS,GAAU,SAAS,cAAc,CAAC;QAAE,MAAM,EAAE;YAAE,EAAE,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC,EAAE,OAAO,YAAY,mBA0ChG;IAEK,SAAS,GAAU,SAAS,cAAc,CAAC;QAAE,MAAM,EAAE;YAAE,EAAE,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC,EAAE,OAAO,YAAY,mBA2BhG;CACH"}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
import "reflect-metadata";
|
|
4
|
-
import path from "path";
|
|
4
|
+
import path from "node:path";
|
|
5
5
|
import { StatusCodes } from "http-status-codes";
|
|
6
|
-
import BaseController from "./base.js";
|
|
7
6
|
import { generateFormFields } from "../../database/dynamic-entity-form-decorators.js";
|
|
8
7
|
import { Helper } from "../../util/index.js";
|
|
8
|
+
import BaseController from "./base.js";
|
|
9
9
|
class EntityController extends BaseController {
|
|
10
10
|
static {
|
|
11
11
|
__name(this, "EntityController");
|
|
12
12
|
}
|
|
13
13
|
// Cache for entity modules to avoid repeated dynamic imports
|
|
14
14
|
static entityCache = /* @__PURE__ */ new Map();
|
|
15
|
+
// Cache for entity properties to avoid repeated prototype iteration
|
|
16
|
+
// biome-ignore lint/complexity/noBannedTypes: WeakMap requires object-type key; Function is the simplest fit for constructor references
|
|
17
|
+
static entityPropertiesCache = /* @__PURE__ */ new WeakMap();
|
|
15
18
|
/**
|
|
16
19
|
* Get request-scoped EntityManager with automatic cleanup
|
|
17
20
|
* Creates a new EM fork per request, cleaned up after response
|
|
@@ -45,19 +48,25 @@ class EntityController extends BaseController {
|
|
|
45
48
|
return EntityClass;
|
|
46
49
|
}, "getEntity");
|
|
47
50
|
getEntityProperties(entityClass) {
|
|
51
|
+
const cached = EntityController.entityPropertiesCache.get(entityClass);
|
|
52
|
+
if (cached) {
|
|
53
|
+
return cached;
|
|
54
|
+
}
|
|
48
55
|
const properties = [];
|
|
49
56
|
const reservedPropertyKeys = ["constructor", "toJSON"];
|
|
50
57
|
for (const propertyKey of Object.getOwnPropertyNames(entityClass.prototype)) {
|
|
51
58
|
if (propertyKey.startsWith("__")) {
|
|
52
59
|
continue;
|
|
53
|
-
}
|
|
60
|
+
}
|
|
61
|
+
if (reservedPropertyKeys.includes(propertyKey)) {
|
|
54
62
|
continue;
|
|
55
63
|
}
|
|
56
64
|
properties.push(propertyKey);
|
|
57
65
|
}
|
|
66
|
+
EntityController.entityPropertiesCache.set(entityClass, properties);
|
|
58
67
|
return properties;
|
|
59
68
|
}
|
|
60
|
-
options = /* @__PURE__ */ __name(async (
|
|
69
|
+
options = /* @__PURE__ */ __name(async (_request, reply) => {
|
|
61
70
|
try {
|
|
62
71
|
const EntityClass = await this.getEntity();
|
|
63
72
|
if (!EntityClass) {
|
|
@@ -75,7 +84,7 @@ class EntityController extends BaseController {
|
|
|
75
84
|
this.sendErrorResponse({ reply, error });
|
|
76
85
|
}
|
|
77
86
|
}, "options");
|
|
78
|
-
metadata = /* @__PURE__ */ __name(async (
|
|
87
|
+
metadata = /* @__PURE__ */ __name(async (_request, reply) => {
|
|
79
88
|
try {
|
|
80
89
|
const EntityClass = await this.getEntity();
|
|
81
90
|
if (!EntityClass) {
|
|
@@ -113,8 +122,8 @@ class EntityController extends BaseController {
|
|
|
113
122
|
this.sendErrorResponse({ reply, error: "Entity not found" });
|
|
114
123
|
return;
|
|
115
124
|
}
|
|
116
|
-
const page = parseInt(request.query.page) || 1;
|
|
117
|
-
const limit = parseInt(request.query.limit);
|
|
125
|
+
const page = parseInt(request.query.page, 10) || 1;
|
|
126
|
+
const limit = parseInt(request.query.limit, 10);
|
|
118
127
|
const offset = (page - 1) * (limit > 0 ? limit : 0);
|
|
119
128
|
const filters = request.query.filters ? JSON.parse(request.query.filters) : {};
|
|
120
129
|
const sortOrder = request.query["sort-order"] || "ASC";
|
|
@@ -124,7 +133,7 @@ class EntityController extends BaseController {
|
|
|
124
133
|
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
125
134
|
continue;
|
|
126
135
|
}
|
|
127
|
-
if (!Object.
|
|
136
|
+
if (!Object.hasOwn(request.query, key)) {
|
|
128
137
|
continue;
|
|
129
138
|
}
|
|
130
139
|
if (key.endsWith("[]")) {
|
|
@@ -151,7 +160,7 @@ class EntityController extends BaseController {
|
|
|
151
160
|
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
152
161
|
continue;
|
|
153
162
|
}
|
|
154
|
-
if (!Object.
|
|
163
|
+
if (!Object.hasOwn(normalizedQuery, key)) {
|
|
155
164
|
continue;
|
|
156
165
|
}
|
|
157
166
|
if (reservedQueryKeys.includes(key)) {
|
|
@@ -205,7 +214,7 @@ class EntityController extends BaseController {
|
|
|
205
214
|
});
|
|
206
215
|
}
|
|
207
216
|
const populate = request.query.populate ? request.query.populate.split(",") : [];
|
|
208
|
-
const [items, total] = await em.findAndCount(
|
|
217
|
+
const [items, total] = await em.findAndCount(EntityClass, options.filters, {
|
|
209
218
|
limit: options.limit,
|
|
210
219
|
offset: options.offset,
|
|
211
220
|
orderBy: options.orderBy,
|
|
@@ -257,7 +266,7 @@ class EntityController extends BaseController {
|
|
|
257
266
|
return;
|
|
258
267
|
}
|
|
259
268
|
const id = request.params.id;
|
|
260
|
-
const item = await em.findOne(
|
|
269
|
+
const item = await em.findOne(EntityClass, { id }, { populate });
|
|
261
270
|
if (!item) {
|
|
262
271
|
return this.sendNotFoundResponse(reply, `${EntityClass.singularNameCapitalized} not found`);
|
|
263
272
|
}
|
|
@@ -301,8 +310,8 @@ class EntityController extends BaseController {
|
|
|
301
310
|
if (error) {
|
|
302
311
|
return this.sendErrorResponse({ reply, error: error.message });
|
|
303
312
|
}
|
|
304
|
-
const item = em.create(
|
|
305
|
-
await em.
|
|
313
|
+
const item = em.create(EntityClass, value);
|
|
314
|
+
await em.persist(item).flush();
|
|
306
315
|
await this.postCreateOne({
|
|
307
316
|
entityManager: em,
|
|
308
317
|
request,
|
|
@@ -329,12 +338,12 @@ class EntityController extends BaseController {
|
|
|
329
338
|
if (error) {
|
|
330
339
|
return this.sendErrorResponse({ reply, error: error.message });
|
|
331
340
|
}
|
|
332
|
-
const item = await em.findOne(
|
|
341
|
+
const item = await em.findOne(EntityClass, { id });
|
|
333
342
|
if (!item) {
|
|
334
343
|
return this.sendNotFoundResponse(reply, `${EntityClass.singularNameCapitalized} not found`);
|
|
335
344
|
}
|
|
336
345
|
em.assign(item, value);
|
|
337
|
-
await em.
|
|
346
|
+
await em.persist(item).flush();
|
|
338
347
|
await this.postUpdateOne({
|
|
339
348
|
entityManager: em,
|
|
340
349
|
request,
|
|
@@ -355,11 +364,11 @@ class EntityController extends BaseController {
|
|
|
355
364
|
return;
|
|
356
365
|
}
|
|
357
366
|
const id = request.params.id;
|
|
358
|
-
const item = await em.findOne(
|
|
367
|
+
const item = await em.findOne(EntityClass, { id });
|
|
359
368
|
if (!item) {
|
|
360
369
|
return this.sendNotFoundResponse(reply, `${EntityClass.singularNameCapitalized} not found`);
|
|
361
370
|
}
|
|
362
|
-
await em.
|
|
371
|
+
await em.remove(item).flush();
|
|
363
372
|
reply.status(StatusCodes.NO_CONTENT).send();
|
|
364
373
|
} catch (error) {
|
|
365
374
|
this.sendErrorResponse({ reply, error });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/webserver/controller/entity.ts"],
|
|
4
|
-
"sourcesContent": ["import 'reflect-metadata';\nimport path from 'path';\nimport type { EntityManager, FilterQuery, Populate } from '@mikro-orm/core';\nimport type { FastifyReply, FastifyRequest } from 'fastify';\nimport { StatusCodes } from 'http-status-codes';\nimport BaseController from './base.js';\nimport type { DynamicEntity } from '../../database/dynamic-entity.js';\nimport { generateFormFields } from '../../database/dynamic-entity-form-decorators.js';\nimport { Helper } from '../../util/index.js';\n\nexport default abstract class EntityController extends BaseController {\n protected abstract entityName: string;\n\n // Cache for entity modules to avoid repeated dynamic imports\n private static entityCache = new Map<string, typeof DynamicEntity>();\n\n /**\n * Get request-scoped EntityManager with automatic cleanup\n * Creates a new EM fork per request, cleaned up after response\n *\n * @internal Used by route handlers, do not call directly\n */\n private getRequestEntityManager(request: FastifyRequest): EntityManager {\n if (!(request as any).__entityManager) {\n (request as any).__entityManager = this.databaseInstance.getEntityManager();\n }\n return (request as any).__entityManager;\n }\n\n protected getEntity = async (): Promise<typeof DynamicEntity | undefined> => {\n if (this.applicationConfig.database?.enabled !== true) {\n throw new Error(`Database not enabled (Entity: ${this.entityName})`);\n }\n\n // Check cache first\n const cacheKey = `${this.applicationConfig.database.entitiesDirectory}:${this.entityName}`;\n if (EntityController.entityCache.has(cacheKey)) {\n return EntityController.entityCache.get(cacheKey);\n }\n\n // Define entity module path\n const entityModulePath = path.join(\n this.applicationConfig.database.entitiesDirectory,\n `${this.entityName}.${Helper.getScriptFileExtension()}`,\n );\n\n // Import entity module\n const entityModule = await import(entityModulePath);\n\n if (!entityModule?.[this.entityName]) {\n throw new Error(`Entity not found (Entity: ${this.entityName})`);\n }\n\n // Get entity class\n const EntityClass = entityModule[this.entityName];\n\n // Cache the entity for future use\n EntityController.entityCache.set(cacheKey, EntityClass);\n\n return EntityClass;\n };\n\n private getEntityProperties(entityClass: any): string[] {\n const properties: string[] = [];\n\n const reservedPropertyKeys = ['constructor', 'toJSON'];\n\n for (const propertyKey of Object.getOwnPropertyNames(entityClass.prototype)) {\n if (propertyKey.startsWith('__')) {\n continue;\n } else if (reservedPropertyKeys.includes(propertyKey)) {\n continue;\n }\n\n properties.push(propertyKey);\n }\n\n return properties;\n }\n\n public options = async (request: FastifyRequest, reply: FastifyReply) => {\n try {\n const EntityClass = await this.getEntity();\n\n if (!EntityClass) {\n this.sendErrorResponse({ reply, error: 'Entity not found' });\n\n return;\n }\n\n const formFields = generateFormFields({ model: EntityClass });\n\n this.sendSuccessResponse({\n reply,\n data: {\n formFields,\n },\n });\n } catch (error) {\n this.sendErrorResponse({ reply, error });\n }\n };\n\n public metadata = async (request: FastifyRequest, reply: FastifyReply) => {\n try {\n const EntityClass = await this.getEntity();\n\n if (!EntityClass) {\n this.sendErrorResponse({ reply, error: 'Entity not found' });\n\n return;\n }\n\n const formFields = generateFormFields({ model: EntityClass });\n\n this.sendSuccessResponse({\n reply,\n data: {\n formFields,\n },\n });\n } catch (error) {\n this.sendErrorResponse({ reply, error });\n }\n };\n\n // Pre-getMany hook (can be overridden in the child controller)\n protected async preGetMany(_: {\n entityManager: EntityManager;\n request: FastifyRequest;\n reply: FastifyReply;\n }): Promise<void> {\n // Default implementation: do nothing\n }\n\n // Post-getMany hook (can be overridden in the child controller)\n // await this.postGetMany({ entityManager: this.entityManager, request, reply, data });\n protected async postGetMany(_: {\n entityManager: EntityManager;\n request: FastifyRequest;\n reply: FastifyReply;\n data: {\n items: any[];\n total: number;\n page: number;\n totalPages: number;\n limit: number;\n };\n }): Promise<void> {\n // Default implementation: do nothing\n }\n\n public getMany = async (\n request: FastifyRequest<{\n Querystring: {\n page: string;\n limit: string;\n filters: string;\n sort: string;\n 'sort-order': string;\n search: string;\n [key: string]: any;\n };\n }>,\n reply: FastifyReply,\n ) => {\n try {\n // Get request-scoped EntityManager\n const em = this.getRequestEntityManager(request);\n\n // Call preGetMany hook\n await this.preGetMany({\n entityManager: em,\n request,\n reply,\n });\n\n const EntityClass = await this.getEntity();\n\n if (!EntityClass) {\n this.sendErrorResponse({ reply, error: 'Entity not found' });\n\n return;\n }\n\n // Pagination parameters\n const page = parseInt(request.query.page) || 1;\n const limit = parseInt(request.query.limit);\n const offset = (page - 1) * (limit > 0 ? limit : 0);\n\n // Filtering and sorting\n const filters = request.query.filters ? JSON.parse(request.query.filters) : {};\n const sortOrder = request.query['sort-order'] || 'ASC';\n const orderBy = request.query.sort ? { [request.query.sort]: sortOrder } : { id: sortOrder };\n\n const normalizedQuery: { [key: string]: any } = {};\n\n for (const key in request.query) {\n // Skip prototype pollution attempts\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') {\n continue;\n }\n\n // Only process own properties\n if (!Object.prototype.hasOwnProperty.call(request.query, key)) {\n continue;\n }\n\n if (key.endsWith('[]')) {\n const normalizedKey = key.slice(0, -2);\n\n // Safe property assignment\n if (normalizedKey !== '__proto__' && normalizedKey !== 'constructor' && normalizedKey !== 'prototype') {\n Reflect.set(normalizedQuery, normalizedKey, Reflect.get(request.query, key));\n }\n } else {\n Reflect.set(normalizedQuery, key, Reflect.get(request.query, key));\n }\n }\n\n // Build query options\n const options: {\n limit?: number;\n offset?: number;\n filters: FilterQuery<any>;\n orderBy: { [key: string]: string };\n } = {\n filters,\n offset,\n orderBy,\n };\n\n if (limit > 0) {\n options.limit = limit;\n }\n\n const entityProperties = this.getEntityProperties(EntityClass);\n const reservedQueryKeys = ['page', 'limit', 'filters', 'sort', 'populate', 'search'];\n const searchQuery = request.query.search || '';\n\n for (const key in normalizedQuery) {\n // Skip prototype pollution attempts\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') {\n continue;\n }\n\n // Only process own properties\n if (!Object.prototype.hasOwnProperty.call(normalizedQuery, key)) {\n continue;\n }\n\n if (reservedQueryKeys.includes(key)) {\n continue;\n }\n\n if (!entityProperties.includes(key)) {\n const [relation, subProperty] = key.split('.');\n\n if (relation && subProperty) {\n // Validate relation and subProperty names\n if (\n relation === '__proto__' ||\n relation === 'constructor' ||\n relation === 'prototype' ||\n subProperty === '__proto__' ||\n subProperty === 'constructor' ||\n subProperty === 'prototype'\n ) {\n continue;\n }\n\n let queryValue = Reflect.get(normalizedQuery, key);\n\n if (!queryValue) continue;\n\n if (typeof queryValue === 'string' && queryValue.includes(',')) {\n queryValue = queryValue.split(',');\n }\n\n if (Array.isArray(queryValue)) {\n Reflect.set(options.filters, relation, {\n [subProperty]: { $in: queryValue },\n });\n } else {\n Reflect.set(options.filters, relation, {\n [subProperty]: queryValue,\n });\n }\n }\n\n continue;\n }\n\n let queryValue = Reflect.get(normalizedQuery, key);\n\n if (!queryValue) {\n continue;\n }\n\n if (typeof queryValue === 'string' && queryValue.includes(',')) {\n queryValue = queryValue.split(',');\n }\n\n if (Array.isArray(queryValue)) {\n Reflect.set(options.filters, key, { $in: queryValue });\n } else {\n Reflect.set(options.filters, key, queryValue);\n }\n }\n\n // Add search filter if a search query is provided\n if (searchQuery) {\n const searchFields = EntityClass.getSearchFields();\n\n options.filters.$or = searchFields\n .filter(field => {\n const isIntegerField = ['id', 'originId'].includes(field);\n\n return !isIntegerField;\n })\n .map(field => {\n return {\n [field]: { $like: `%${searchQuery}%` },\n };\n });\n }\n\n const populate = request.query.populate ? request.query.populate.split(',') : [];\n\n // Fetch items from the database\n const [items, total] = await em.findAndCount(this.entityName, options.filters, {\n limit: options.limit,\n offset: options.offset,\n orderBy: options.orderBy,\n populate,\n });\n\n const totalPages = limit > 0 ? Math.ceil(total / limit) : 1;\n\n const data = {\n items,\n total,\n page,\n totalPages,\n limit: limit > 0 ? limit : total,\n };\n\n // Call postGetMany hook\n await this.postGetMany({\n entityManager: em,\n request,\n reply,\n data,\n });\n\n reply.send({\n data: data.items,\n total_items: data.total,\n page: data.page,\n total_pages: data.totalPages,\n limit: data.limit,\n });\n } catch (error) {\n this.sendErrorResponse({ reply, error });\n }\n };\n\n protected async preGetOne(_: {\n entityManager: EntityManager;\n request: FastifyRequest;\n reply: FastifyReply;\n }): Promise<void> {\n // Default implementation: do nothing\n }\n\n protected async postGetOne(_: {\n entityManager: EntityManager;\n request: FastifyRequest;\n reply: FastifyReply;\n item: any;\n }): Promise<void> {\n // Default implementation: do nothing\n }\n\n public getOne = async (\n request: FastifyRequest<{\n Params: { id: number };\n Querystring: { populate: string };\n }>,\n reply: FastifyReply,\n ) => {\n try {\n // Get request-scoped EntityManager\n const em = this.getRequestEntityManager(request);\n\n await this.preGetOne({\n entityManager: em,\n request,\n reply,\n });\n\n const queryPopulate = request.query.populate || null;\n const populateList: string[] = queryPopulate ? queryPopulate.split(',') : [];\n\n // Ensure populate is typed correctly for MikroORM\n const populate = populateList.map(field => `${field}.*`) as unknown as Populate<\n object,\n `${string}.*` | `${string}.$infer`\n >;\n\n const EntityClass = await this.getEntity();\n\n if (!EntityClass) {\n this.sendErrorResponse({ reply, error: 'Entity not found' });\n return;\n }\n\n const id = request.params.id;\n\n const item = await em.findOne(this.entityName, { id }, { populate });\n\n if (!item) {\n return this.sendNotFoundResponse(reply, `${EntityClass.singularNameCapitalized} not found`);\n }\n\n await this.postGetOne({\n entityManager: em,\n request,\n reply,\n item,\n });\n\n this.sendSuccessResponse({ reply, data: item });\n } catch (error) {\n this.sendErrorResponse({ reply, error });\n }\n };\n\n protected preCreateOne = ({\n request,\n reply,\n }: {\n request: FastifyRequest;\n reply: FastifyReply;\n }): { request: FastifyRequest; reply: FastifyReply } => {\n return { request, reply };\n };\n\n protected async postCreateOne(_: {\n entityManager: EntityManager;\n request: FastifyRequest;\n reply: FastifyReply;\n item: any;\n }): Promise<void> {}\n\n public createOne = async (request: FastifyRequest, reply: FastifyReply) => {\n try {\n // Get request-scoped EntityManager\n const em = this.getRequestEntityManager(request);\n\n const EntityClass = await this.getEntity();\n\n if (!EntityClass) {\n this.sendErrorResponse({ reply, error: 'Entity not found' });\n return;\n }\n\n // Listen for preCreateOne hook\n if (this.preCreateOne) {\n const { request: preCreateOneRequest } = await this.preCreateOne({\n request,\n reply,\n });\n if (preCreateOneRequest) {\n request = preCreateOneRequest;\n }\n }\n\n const { error, value } = EntityClass.validateCreate(request.body);\n\n if (error) {\n return this.sendErrorResponse({ reply, error: error.message });\n }\n\n const item = em.create(this.entityName, value as object);\n\n await em.persistAndFlush(item);\n\n // Call postCreateOne hook\n await this.postCreateOne({\n entityManager: em,\n request,\n reply,\n item,\n });\n\n this.sendSuccessResponse({ reply, data: item, statusCode: StatusCodes.CREATED });\n } catch (error) {\n this.sendErrorResponse({ reply, error });\n }\n };\n\n protected async postUpdateOne(_: {\n entityManager: EntityManager;\n request: FastifyRequest;\n reply: FastifyReply;\n item: any;\n }): Promise<void> {}\n\n public updateOne = async (request: FastifyRequest<{ Params: { id: number } }>, reply: FastifyReply) => {\n try {\n // Get request-scoped EntityManager\n const em = this.getRequestEntityManager(request);\n\n const EntityClass = await this.getEntity();\n\n if (!EntityClass) {\n this.sendErrorResponse({ reply, error: 'Entity not found' });\n return;\n }\n\n const id = request.params.id;\n\n const { error, value } = EntityClass.validateUpdate(request.body);\n\n if (error) {\n return this.sendErrorResponse({ reply, error: error.message });\n }\n\n const item = await em.findOne(this.entityName, { id });\n\n if (!item) {\n return this.sendNotFoundResponse(reply, `${EntityClass.singularNameCapitalized} not found`);\n }\n\n em.assign(item, value as object);\n\n await em.persistAndFlush(item);\n\n // Call postUpdateOne hook\n await this.postUpdateOne({\n entityManager: em,\n request,\n reply,\n item,\n });\n\n this.sendSuccessResponse({ reply, data: item });\n } catch (error) {\n this.sendErrorResponse({ reply, error });\n }\n };\n\n public deleteOne = async (request: FastifyRequest<{ Params: { id: number } }>, reply: FastifyReply) => {\n try {\n // Get request-scoped EntityManager\n const em = this.getRequestEntityManager(request);\n\n const EntityClass = await this.getEntity();\n\n if (!EntityClass) {\n this.sendErrorResponse({ reply, error: 'Entity not found' });\n\n return;\n }\n\n const id = request.params.id;\n\n const item = await em.findOne(this.entityName, { id });\n\n if (!item) {\n return this.sendNotFoundResponse(reply, `${EntityClass.singularNameCapitalized} not found`);\n }\n\n await em.removeAndFlush(item);\n\n reply.status(StatusCodes.NO_CONTENT).send();\n } catch (error) {\n this.sendErrorResponse({ reply, error });\n }\n };\n}\n"],
|
|
5
|
-
"mappings": ";;AAAA,OAAO;AACP,OAAO,UAAU;AAGjB,SAAS,mBAAmB;
|
|
4
|
+
"sourcesContent": ["import 'reflect-metadata';\nimport path from 'node:path';\nimport type { EntityManager, FilterQuery, Populate } from '@mikro-orm/core';\nimport type { FastifyReply, FastifyRequest } from 'fastify';\nimport { StatusCodes } from 'http-status-codes';\nimport type { DynamicEntity } from '../../database/dynamic-entity.js';\nimport { generateFormFields } from '../../database/dynamic-entity-form-decorators.js';\nimport { Helper } from '../../util/index.js';\nimport BaseController from './base.js';\n\nexport default abstract class EntityController extends BaseController {\n protected abstract entityName: string;\n\n // Cache for entity modules to avoid repeated dynamic imports\n private static entityCache = new Map<string, typeof DynamicEntity>();\n\n // Cache for entity properties to avoid repeated prototype iteration\n // biome-ignore lint/complexity/noBannedTypes: WeakMap requires object-type key; Function is the simplest fit for constructor references\n private static entityPropertiesCache = new WeakMap<Function, string[]>();\n\n /**\n * Get request-scoped EntityManager with automatic cleanup\n * Creates a new EM fork per request, cleaned up after response\n *\n * @internal Used by route handlers, do not call directly\n */\n private getRequestEntityManager(request: FastifyRequest): EntityManager {\n if (!(request as any).__entityManager) {\n (request as any).__entityManager = this.databaseInstance.getEntityManager();\n }\n return (request as any).__entityManager;\n }\n\n protected getEntity = async (): Promise<typeof DynamicEntity | undefined> => {\n if (this.applicationConfig.database?.enabled !== true) {\n throw new Error(`Database not enabled (Entity: ${this.entityName})`);\n }\n\n // Check cache first\n const cacheKey = `${this.applicationConfig.database.entitiesDirectory}:${this.entityName}`;\n if (EntityController.entityCache.has(cacheKey)) {\n return EntityController.entityCache.get(cacheKey);\n }\n\n // Define entity module path\n const entityModulePath = path.join(\n this.applicationConfig.database.entitiesDirectory,\n `${this.entityName}.${Helper.getScriptFileExtension()}`,\n );\n\n // Import entity module\n const entityModule = await import(entityModulePath);\n\n if (!entityModule?.[this.entityName]) {\n throw new Error(`Entity not found (Entity: ${this.entityName})`);\n }\n\n // Get entity class\n const EntityClass = entityModule[this.entityName];\n\n // Cache the entity for future use\n EntityController.entityCache.set(cacheKey, EntityClass);\n\n return EntityClass;\n };\n\n private getEntityProperties(entityClass: any): string[] {\n // Check cache first to avoid repeated prototype iteration\n const cached = EntityController.entityPropertiesCache.get(entityClass);\n if (cached) {\n return cached;\n }\n\n const properties: string[] = [];\n\n const reservedPropertyKeys = ['constructor', 'toJSON'];\n\n for (const propertyKey of Object.getOwnPropertyNames(entityClass.prototype)) {\n if (propertyKey.startsWith('__')) {\n continue;\n }\n if (reservedPropertyKeys.includes(propertyKey)) {\n continue;\n }\n\n properties.push(propertyKey);\n }\n\n // Cache the result for future calls\n EntityController.entityPropertiesCache.set(entityClass, properties);\n\n return properties;\n }\n\n public options = async (_request: FastifyRequest, reply: FastifyReply) => {\n try {\n const EntityClass = await this.getEntity();\n\n if (!EntityClass) {\n this.sendErrorResponse({ reply, error: 'Entity not found' });\n\n return;\n }\n\n const formFields = generateFormFields({ model: EntityClass });\n\n this.sendSuccessResponse({\n reply,\n data: {\n formFields,\n },\n });\n } catch (error) {\n this.sendErrorResponse({ reply, error });\n }\n };\n\n public metadata = async (_request: FastifyRequest, reply: FastifyReply) => {\n try {\n const EntityClass = await this.getEntity();\n\n if (!EntityClass) {\n this.sendErrorResponse({ reply, error: 'Entity not found' });\n\n return;\n }\n\n const formFields = generateFormFields({ model: EntityClass });\n\n this.sendSuccessResponse({\n reply,\n data: {\n formFields,\n },\n });\n } catch (error) {\n this.sendErrorResponse({ reply, error });\n }\n };\n\n // Pre-getMany hook (can be overridden in the child controller)\n protected async preGetMany(_: {\n entityManager: EntityManager;\n request: FastifyRequest;\n reply: FastifyReply;\n }): Promise<void> {\n // Default implementation: do nothing\n }\n\n // Post-getMany hook (can be overridden in the child controller)\n // await this.postGetMany({ entityManager: this.entityManager, request, reply, data });\n protected async postGetMany(_: {\n entityManager: EntityManager;\n request: FastifyRequest;\n reply: FastifyReply;\n data: {\n items: any[];\n total: number;\n page: number;\n totalPages: number;\n limit: number;\n };\n }): Promise<void> {\n // Default implementation: do nothing\n }\n\n public getMany = async (\n request: FastifyRequest<{\n Querystring: {\n page: string;\n limit: string;\n filters: string;\n sort: string;\n 'sort-order': string;\n search: string;\n [key: string]: any;\n };\n }>,\n reply: FastifyReply,\n ) => {\n try {\n // Get request-scoped EntityManager\n const em = this.getRequestEntityManager(request);\n\n // Call preGetMany hook\n await this.preGetMany({\n entityManager: em,\n request,\n reply,\n });\n\n const EntityClass = await this.getEntity();\n\n if (!EntityClass) {\n this.sendErrorResponse({ reply, error: 'Entity not found' });\n\n return;\n }\n\n // Pagination parameters\n const page = parseInt(request.query.page, 10) || 1;\n const limit = parseInt(request.query.limit, 10);\n const offset = (page - 1) * (limit > 0 ? limit : 0);\n\n // Filtering and sorting\n const filters = request.query.filters ? JSON.parse(request.query.filters) : {};\n const sortOrder = request.query['sort-order'] || 'ASC';\n const orderBy = request.query.sort ? { [request.query.sort]: sortOrder } : { id: sortOrder };\n\n const normalizedQuery: { [key: string]: any } = {};\n\n for (const key in request.query) {\n // Skip prototype pollution attempts\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') {\n continue;\n }\n\n // Only process own properties\n if (!Object.hasOwn(request.query, key)) {\n continue;\n }\n\n if (key.endsWith('[]')) {\n const normalizedKey = key.slice(0, -2);\n\n // Safe property assignment\n if (normalizedKey !== '__proto__' && normalizedKey !== 'constructor' && normalizedKey !== 'prototype') {\n Reflect.set(normalizedQuery, normalizedKey, Reflect.get(request.query, key));\n }\n } else {\n Reflect.set(normalizedQuery, key, Reflect.get(request.query, key));\n }\n }\n\n // Build query options\n const options: {\n limit?: number;\n offset?: number;\n filters: FilterQuery<any>;\n orderBy: { [key: string]: string };\n } = {\n filters,\n offset,\n orderBy,\n };\n\n if (limit > 0) {\n options.limit = limit;\n }\n\n const entityProperties = this.getEntityProperties(EntityClass);\n const reservedQueryKeys = ['page', 'limit', 'filters', 'sort', 'populate', 'search'];\n const searchQuery = request.query.search || '';\n\n for (const key in normalizedQuery) {\n // Skip prototype pollution attempts\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') {\n continue;\n }\n\n // Only process own properties\n if (!Object.hasOwn(normalizedQuery, key)) {\n continue;\n }\n\n if (reservedQueryKeys.includes(key)) {\n continue;\n }\n\n if (!entityProperties.includes(key)) {\n const [relation, subProperty] = key.split('.');\n\n if (relation && subProperty) {\n // Validate relation and subProperty names\n if (\n relation === '__proto__' ||\n relation === 'constructor' ||\n relation === 'prototype' ||\n subProperty === '__proto__' ||\n subProperty === 'constructor' ||\n subProperty === 'prototype'\n ) {\n continue;\n }\n\n let queryValue = Reflect.get(normalizedQuery, key);\n\n if (!queryValue) continue;\n\n if (typeof queryValue === 'string' && queryValue.includes(',')) {\n queryValue = queryValue.split(',');\n }\n\n if (Array.isArray(queryValue)) {\n Reflect.set(options.filters, relation, {\n [subProperty]: { $in: queryValue },\n });\n } else {\n Reflect.set(options.filters, relation, {\n [subProperty]: queryValue,\n });\n }\n }\n\n continue;\n }\n\n let queryValue = Reflect.get(normalizedQuery, key);\n\n if (!queryValue) {\n continue;\n }\n\n if (typeof queryValue === 'string' && queryValue.includes(',')) {\n queryValue = queryValue.split(',');\n }\n\n if (Array.isArray(queryValue)) {\n Reflect.set(options.filters, key, { $in: queryValue });\n } else {\n Reflect.set(options.filters, key, queryValue);\n }\n }\n\n // Add search filter if a search query is provided\n if (searchQuery) {\n const searchFields = EntityClass.getSearchFields();\n\n options.filters.$or = searchFields\n .filter(field => {\n const isIntegerField = ['id', 'originId'].includes(field);\n\n return !isIntegerField;\n })\n .map(field => {\n return {\n [field]: { $like: `%${searchQuery}%` },\n };\n });\n }\n\n const populate = request.query.populate ? request.query.populate.split(',') : [];\n\n // Fetch items from the database\n const [items, total] = await em.findAndCount(EntityClass as any, options.filters, {\n limit: options.limit,\n offset: options.offset,\n orderBy: options.orderBy,\n populate,\n });\n\n const totalPages = limit > 0 ? Math.ceil(total / limit) : 1;\n\n const data = {\n items,\n total,\n page,\n totalPages,\n limit: limit > 0 ? limit : total,\n };\n\n // Call postGetMany hook\n await this.postGetMany({\n entityManager: em,\n request,\n reply,\n data,\n });\n\n reply.send({\n data: data.items,\n total_items: data.total,\n page: data.page,\n total_pages: data.totalPages,\n limit: data.limit,\n });\n } catch (error) {\n this.sendErrorResponse({ reply, error });\n }\n };\n\n protected async preGetOne(_: {\n entityManager: EntityManager;\n request: FastifyRequest;\n reply: FastifyReply;\n }): Promise<void> {\n // Default implementation: do nothing\n }\n\n protected async postGetOne(_: {\n entityManager: EntityManager;\n request: FastifyRequest;\n reply: FastifyReply;\n item: any;\n }): Promise<void> {\n // Default implementation: do nothing\n }\n\n public getOne = async (\n request: FastifyRequest<{\n Params: { id: number };\n Querystring: { populate: string };\n }>,\n reply: FastifyReply,\n ) => {\n try {\n // Get request-scoped EntityManager\n const em = this.getRequestEntityManager(request);\n\n await this.preGetOne({\n entityManager: em,\n request,\n reply,\n });\n\n const queryPopulate = request.query.populate || null;\n const populateList: string[] = queryPopulate ? queryPopulate.split(',') : [];\n\n // Ensure populate is typed correctly for MikroORM\n const populate = populateList.map(field => `${field}.*`) as unknown as Populate<\n object,\n `${string}.*` | `${string}.$infer`\n >;\n\n const EntityClass = await this.getEntity();\n\n if (!EntityClass) {\n this.sendErrorResponse({ reply, error: 'Entity not found' });\n return;\n }\n\n const id = request.params.id;\n\n const item = await em.findOne(EntityClass as any, { id }, { populate });\n\n if (!item) {\n return this.sendNotFoundResponse(reply, `${EntityClass.singularNameCapitalized} not found`);\n }\n\n await this.postGetOne({\n entityManager: em,\n request,\n reply,\n item,\n });\n\n this.sendSuccessResponse({ reply, data: item });\n } catch (error) {\n this.sendErrorResponse({ reply, error });\n }\n };\n\n protected preCreateOne = ({\n request,\n reply,\n }: {\n request: FastifyRequest;\n reply: FastifyReply;\n }): { request: FastifyRequest; reply: FastifyReply } => {\n return { request, reply };\n };\n\n protected async postCreateOne(_: {\n entityManager: EntityManager;\n request: FastifyRequest;\n reply: FastifyReply;\n item: any;\n }): Promise<void> {}\n\n public createOne = async (request: FastifyRequest, reply: FastifyReply) => {\n try {\n // Get request-scoped EntityManager\n const em = this.getRequestEntityManager(request);\n\n const EntityClass = await this.getEntity();\n\n if (!EntityClass) {\n this.sendErrorResponse({ reply, error: 'Entity not found' });\n return;\n }\n\n // Listen for preCreateOne hook\n if (this.preCreateOne) {\n const { request: preCreateOneRequest } = await this.preCreateOne({\n request,\n reply,\n });\n if (preCreateOneRequest) {\n request = preCreateOneRequest;\n }\n }\n\n const { error, value } = EntityClass.validateCreate(request.body);\n\n if (error) {\n return this.sendErrorResponse({ reply, error: error.message });\n }\n\n const item = em.create(EntityClass as any, value as object);\n\n await em.persist(item).flush();\n\n // Call postCreateOne hook\n await this.postCreateOne({\n entityManager: em,\n request,\n reply,\n item,\n });\n\n this.sendSuccessResponse({ reply, data: item, statusCode: StatusCodes.CREATED });\n } catch (error) {\n this.sendErrorResponse({ reply, error });\n }\n };\n\n protected async postUpdateOne(_: {\n entityManager: EntityManager;\n request: FastifyRequest;\n reply: FastifyReply;\n item: any;\n }): Promise<void> {}\n\n public updateOne = async (request: FastifyRequest<{ Params: { id: number } }>, reply: FastifyReply) => {\n try {\n // Get request-scoped EntityManager\n const em = this.getRequestEntityManager(request);\n\n const EntityClass = await this.getEntity();\n\n if (!EntityClass) {\n this.sendErrorResponse({ reply, error: 'Entity not found' });\n return;\n }\n\n const id = request.params.id;\n\n const { error, value } = EntityClass.validateUpdate(request.body);\n\n if (error) {\n return this.sendErrorResponse({ reply, error: error.message });\n }\n\n const item = await em.findOne(EntityClass as any, { id });\n\n if (!item) {\n return this.sendNotFoundResponse(reply, `${EntityClass.singularNameCapitalized} not found`);\n }\n\n em.assign(item, value as object);\n\n await em.persist(item).flush();\n\n // Call postUpdateOne hook\n await this.postUpdateOne({\n entityManager: em,\n request,\n reply,\n item,\n });\n\n this.sendSuccessResponse({ reply, data: item });\n } catch (error) {\n this.sendErrorResponse({ reply, error });\n }\n };\n\n public deleteOne = async (request: FastifyRequest<{ Params: { id: number } }>, reply: FastifyReply) => {\n try {\n // Get request-scoped EntityManager\n const em = this.getRequestEntityManager(request);\n\n const EntityClass = await this.getEntity();\n\n if (!EntityClass) {\n this.sendErrorResponse({ reply, error: 'Entity not found' });\n\n return;\n }\n\n const id = request.params.id;\n\n const item = await em.findOne(EntityClass as any, { id });\n\n if (!item) {\n return this.sendNotFoundResponse(reply, `${EntityClass.singularNameCapitalized} not found`);\n }\n\n await em.remove(item).flush();\n\n reply.status(StatusCodes.NO_CONTENT).send();\n } catch (error) {\n this.sendErrorResponse({ reply, error });\n }\n };\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA,OAAO;AACP,OAAO,UAAU;AAGjB,SAAS,mBAAmB;AAE5B,SAAS,0BAA0B;AACnC,SAAS,cAAc;AACvB,OAAO,oBAAoB;AAE3B,MAAO,yBAAgD,eAAe;AAAA,EAVtE,OAUsE;AAAA;AAAA;AAAA;AAAA,EAIpE,OAAe,cAAc,oBAAI,IAAkC;AAAA;AAAA;AAAA,EAInE,OAAe,wBAAwB,oBAAI,QAA4B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ/D,wBAAwB,SAAwC;AACtE,QAAI,CAAE,QAAgB,iBAAiB;AACrC,MAAC,QAAgB,kBAAkB,KAAK,iBAAiB,iBAAiB;AAAA,IAC5E;AACA,WAAQ,QAAgB;AAAA,EAC1B;AAAA,EAEU,Y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5F;AAEA,SAAG,OAAO,MAAM,KAAe;AAE/B,YAAM,GAAG,QAAQ,IAAI,EAAE,MAAM;AAG7B,YAAM,KAAK,cAAc;AAAA,QACvB,eAAe;AAAA,QACf;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAED,WAAK,oBAAoB,EAAE,OAAO,MAAM,KAAK,CAAC;AAAA,IAChD,SAAS,OAAO;AACd,WAAK,kBAAkB,EAAE,OAAO,MAAM,CAAC;AAAA,IACzC;AAAA,EACF,GA1CmB;AAAA,EA4CZ,YAAY,8BAAO,SAAqD,UAAwB;AACrG,QAAI;AAEF,YAAM,KAAK,KAAK,wBAAwB,OAAO;AAE/C,YAAM,cAAc,MAAM,KAAK,UAAU;AAEzC,UAAI,CAAC,aAAa;AAChB,aAAK,kBAAkB,EAAE,OAAO,OAAO,mBAAmB,CAAC;AAE3D;AAAA,MACF;AAEA,YAAM,KAAK,QAAQ,OAAO;AAE1B,YAAM,OAAO,MAAM,GAAG,QAAQ,aAAoB,EAAE,GAAG,CAAC;AAExD,UAAI,CAAC,MAAM;AACT,eAAO,KAAK,qBAAqB,OAAO,GAAG,YAAY,uBAAuB,YAAY;AAAA,MAC5F;AAEA,YAAM,GAAG,OAAO,IAAI,EAAE,MAAM;AAE5B,YAAM,OAAO,YAAY,UAAU,EAAE,KAAK;AAAA,IAC5C,SAAS,OAAO;AACd,WAAK,kBAAkB,EAAE,OAAO,MAAM,CAAC;AAAA,IACzC;AAAA,EACF,GA3BmB;AA4BrB;",
|
|
6
6
|
"names": ["queryValue"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"example-auth.d.ts","sourceRoot":"","sources":["../../../src/webserver/controller/example-auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"example-auth.d.ts","sourceRoot":"","sources":["../../../src/webserver/controller/example-auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,uBAAmD,MAAM,WAAW,CAAC;AAE5E;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,qBAAsB,SAAQ,uBAAuB;IAEjE,cAAc,8CAWmB;IAGjC,aAAa,GAAU,SAAS,cAAc,EAAE,OAAO,YAAY,KAAG,OAAO,CAAC,IAAI,CAAC,CAexF;IAGK,cAAc,GAAU,SAAS,cAAc,EAAE,OAAO,YAAY,KAAG,OAAO,CAAC,IAAI,CAAC,CAWzF;YAGY,kBAAkB;CAcjC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import WebServerBaseController from "./base.js";
|
|
4
3
|
import { withAuth } from "./auth-middleware.js";
|
|
4
|
+
import WebServerBaseController from "./base.js";
|
|
5
5
|
class ExampleAuthController extends WebServerBaseController {
|
|
6
6
|
static {
|
|
7
7
|
__name(this, "ExampleAuthController");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/webserver/controller/example-auth.ts"],
|
|
4
|
-
"sourcesContent": ["import type { FastifyReply, FastifyRequest } from 'fastify';\nimport
|
|
5
|
-
"mappings": ";;AACA,
|
|
4
|
+
"sourcesContent": ["import type { FastifyReply, FastifyRequest } from 'fastify';\nimport { type AuthenticatedRequest, withAuth } from './auth-middleware.js';\nimport WebServerBaseController, { type AuthenticatedUser } from './base.js';\n\n/**\n * Example controller demonstrating simplified authentication\n */\nexport default class ExampleAuthController extends WebServerBaseController {\n // Method 1: Using wrapper function approach\n public getUserTickers = withAuth(async (request: AuthenticatedRequest, reply: FastifyReply): Promise<void> => {\n // User is automatically authenticated and available on request.user\n const { userId } = request.user;\n\n // Your business logic here\n const tickers = [\n { id: 1, symbol: 'AAPL', userId },\n { id: 2, symbol: 'GOOGL', userId },\n ];\n\n return this.sendSuccessResponse({ reply, data: tickers });\n }, this.authenticateRequest.bind(this));\n\n // Method 2: Manual authentication (original approach, now simplified)\n public getUserOrders = async (request: FastifyRequest, reply: FastifyReply): Promise<void> => {\n const user = await this.authenticateRequest(request, reply);\n\n if (!user) {\n // Authentication failed, response already sent\n return;\n }\n\n // Your business logic here\n const orders = [\n { id: 1, userId: user.userId, symbol: 'AAPL', quantity: 10 },\n { id: 2, userId: user.userId, symbol: 'GOOGL', quantity: 5 },\n ];\n\n return this.sendSuccessResponse({ reply, data: orders });\n };\n\n // Method 3: Creating a simple authenticated wrapper method\n public getUserProfile = async (request: FastifyRequest, reply: FastifyReply): Promise<void> => {\n return this.withAuthentication(request, reply, async user => {\n // Your business logic here with authenticated user\n const userProfile = {\n userId: user.userId,\n username: user.payload.username ?? 'N/A',\n email: user.payload.email ?? 'N/A',\n };\n\n return this.sendSuccessResponse({ reply, data: userProfile });\n });\n };\n\n // Helper method for inline authentication\n private async withAuthentication(\n request: FastifyRequest,\n reply: FastifyReply,\n handler: (user: AuthenticatedUser) => Promise<void>,\n ): Promise<void> {\n const user = await this.authenticateRequest(request, reply);\n\n if (!user) {\n // Authentication failed, response already sent\n return;\n }\n\n return handler(user);\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AACA,SAAoC,gBAAgB;AACpD,OAAO,6BAAyD;AAKhE,MAAO,8BAA4C,wBAAwB;AAAA,EAP3E,OAO2E;AAAA;AAAA;AAAA;AAAA,EAElE,iBAAiB,SAAS,OAAO,SAA+B,UAAuC;AAE5G,UAAM,EAAE,OAAO,IAAI,QAAQ;AAG3B,UAAM,UAAU;AAAA,MACd,EAAE,IAAI,GAAG,QAAQ,QAAQ,OAAO;AAAA,MAChC,EAAE,IAAI,GAAG,QAAQ,SAAS,OAAO;AAAA,IACnC;AAEA,WAAO,KAAK,oBAAoB,EAAE,OAAO,MAAM,QAAQ,CAAC;AAAA,EAC1D,GAAG,KAAK,oBAAoB,KAAK,IAAI,CAAC;AAAA;AAAA,EAG/B,gBAAgB,8BAAO,SAAyB,UAAuC;AAC5F,UAAM,OAAO,MAAM,KAAK,oBAAoB,SAAS,KAAK;AAE1D,QAAI,CAAC,MAAM;AAET;AAAA,IACF;AAGA,UAAM,SAAS;AAAA,MACb,EAAE,IAAI,GAAG,QAAQ,KAAK,QAAQ,QAAQ,QAAQ,UAAU,GAAG;AAAA,MAC3D,EAAE,IAAI,GAAG,QAAQ,KAAK,QAAQ,QAAQ,SAAS,UAAU,EAAE;AAAA,IAC7D;AAEA,WAAO,KAAK,oBAAoB,EAAE,OAAO,MAAM,OAAO,CAAC;AAAA,EACzD,GAfuB;AAAA;AAAA,EAkBhB,iBAAiB,8BAAO,SAAyB,UAAuC;AAC7F,WAAO,KAAK,mBAAmB,SAAS,OAAO,OAAM,SAAQ;AAE3D,YAAM,cAAc;AAAA,QAClB,QAAQ,KAAK;AAAA,QACb,UAAU,KAAK,QAAQ,YAAY;AAAA,QACnC,OAAO,KAAK,QAAQ,SAAS;AAAA,MAC/B;AAEA,aAAO,KAAK,oBAAoB,EAAE,OAAO,MAAM,YAAY,CAAC;AAAA,IAC9D,CAAC;AAAA,EACH,GAXwB;AAAA;AAAA,EAcxB,MAAc,mBACZ,SACA,OACA,SACe;AACf,UAAM,OAAO,MAAM,KAAK,oBAAoB,SAAS,KAAK;AAE1D,QAAI,CAAC,MAAM;AAET;AAAA,IACF;AAEA,WAAO,QAAQ,IAAI;AAAA,EACrB;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../../src/webserver/controller/health.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../../src/webserver/controller/health.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,cAAc,MAAM,WAAW,CAAC;AAEvC,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,cAAc;IAC1D;;OAEG;IACI,IAAI,GAAU,GAAG,cAAc,EAAE,OAAO,YAAY,KAAG,OAAO,CAAC,IAAI,CAAC,CAQzE;IAEF;;OAEG;IACI,KAAK,GAAU,GAAG,cAAc,EAAE,OAAO,YAAY,KAAG,OAAO,CAAC,IAAI,CAAC,CA6B1E;CACH"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import BaseController from "./base.js";
|
|
4
3
|
import { LifecyclePhase } from "../../lifecycle/types.js";
|
|
4
|
+
import BaseController from "./base.js";
|
|
5
5
|
class HealthController extends BaseController {
|
|
6
6
|
static {
|
|
7
7
|
__name(this, "HealthController");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/webserver/controller/health.ts"],
|
|
4
|
-
"sourcesContent": ["import type { FastifyReply, FastifyRequest } from 'fastify';\nimport
|
|
5
|
-
"mappings": ";;AACA,
|
|
4
|
+
"sourcesContent": ["import type { FastifyReply, FastifyRequest } from 'fastify';\nimport { LifecyclePhase } from '../../lifecycle/types.js';\nimport BaseController from './base.js';\n\nexport default class HealthController extends BaseController {\n /**\n * Liveness probe: process is up and not in stopping phase.\n */\n public live = async (_: FastifyRequest, reply: FastifyReply): Promise<void> => {\n const phase = this.lifecycleManager.phase;\n const shuttingDown = phase === LifecyclePhase.STOPPING || phase === LifecyclePhase.STOPPED;\n if (shuttingDown) {\n reply.code(503).send({ live: false, phase });\n return;\n }\n reply.send({ live: true, phase });\n };\n\n /**\n * Readiness probe: service dependencies are available & lifecycle is RUNNING with aggregated readiness.\n */\n public ready = async (_: FastifyRequest, reply: FastifyReply): Promise<void> => {\n const phase = this.lifecycleManager.phase;\n const readinessStatus = await this.lifecycleManager.getReadinessStatus();\n\n // Convert readiness check results to probe format\n const probes: Record<string, { healthy: boolean; required: boolean }> = {};\n for (const check of readinessStatus.checks) {\n probes[check.name] = { healthy: check.ready, required: true };\n }\n\n const requiredFailures = Object.entries(probes)\n .filter(([, v]) => v.required && !v.healthy)\n .map(([k]) => k);\n\n const ready = readinessStatus.ready;\n\n if (!ready) {\n reply.code(503).send({\n ready: false,\n phase,\n probes,\n notReady: phase !== LifecyclePhase.RUNNING ? 'lifecycle-phase' : 'readiness-checks-failed',\n failed: requiredFailures,\n aggregatedReadiness: true,\n });\n return;\n }\n\n reply.send({ ready: true, phase, probes, aggregatedReadiness: true });\n };\n}\n"],
|
|
5
|
+
"mappings": ";;AACA,SAAS,sBAAsB;AAC/B,OAAO,oBAAoB;AAE3B,MAAO,yBAAuC,eAAe;AAAA,EAJ7D,OAI6D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAIpD,OAAO,8BAAO,GAAmB,UAAuC;AAC7E,UAAM,QAAQ,KAAK,iBAAiB;AACpC,UAAM,eAAe,UAAU,eAAe,YAAY,UAAU,eAAe;AACnF,QAAI,cAAc;AAChB,YAAM,KAAK,GAAG,EAAE,KAAK,EAAE,MAAM,OAAO,MAAM,CAAC;AAC3C;AAAA,IACF;AACA,UAAM,KAAK,EAAE,MAAM,MAAM,MAAM,CAAC;AAAA,EAClC,GARc;AAAA;AAAA;AAAA;AAAA,EAaP,QAAQ,8BAAO,GAAmB,UAAuC;AAC9E,UAAM,QAAQ,KAAK,iBAAiB;AACpC,UAAM,kBAAkB,MAAM,KAAK,iBAAiB,mBAAmB;AAGvE,UAAM,SAAkE,CAAC;AACzE,eAAW,SAAS,gBAAgB,QAAQ;AAC1C,aAAO,MAAM,IAAI,IAAI,EAAE,SAAS,MAAM,OAAO,UAAU,KAAK;AAAA,IAC9D;AAE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