@scpxl/nodejs-framework 1.0.50 → 1.0.57
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/LICENSE +1 -1
- package/README.md +14 -9
- 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 +17 -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/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 +3 -2
- package/dist/queue/manager.d.ts.map +1 -1
- package/dist/queue/manager.js +5 -2
- 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.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 +1 -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 +4 -4
- package/dist/redis/index.js.map +2 -2
- package/dist/redis/manager.d.ts +2 -1
- package/dist/redis/manager.d.ts.map +1 -1
- package/dist/redis/manager.js +7 -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 +0 -6
- 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 +3 -3
- package/dist/webserver/controller/entity.d.ts.map +1 -1
- package/dist/webserver/controller/entity.js +19 -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.map +1 -1
- package/dist/websocket/websocket-client-manager.js +3 -3
- package/dist/websocket/websocket-client-manager.js.map +2 -2
- package/dist/websocket/websocket-client.d.ts +5 -5
- package/dist/websocket/websocket-client.d.ts.map +1 -1
- package/dist/websocket/websocket-client.js +5 -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 +69 -65
|
@@ -1,11 +1,11 @@
|
|
|
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");
|
|
@@ -13,6 +13,7 @@ class EntityController extends BaseController {
|
|
|
13
13
|
// Cache for entity modules to avoid repeated dynamic imports
|
|
14
14
|
static entityCache = /* @__PURE__ */ new Map();
|
|
15
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
|
|
16
17
|
static entityPropertiesCache = /* @__PURE__ */ new WeakMap();
|
|
17
18
|
/**
|
|
18
19
|
* Get request-scoped EntityManager with automatic cleanup
|
|
@@ -56,7 +57,8 @@ class EntityController extends BaseController {
|
|
|
56
57
|
for (const propertyKey of Object.getOwnPropertyNames(entityClass.prototype)) {
|
|
57
58
|
if (propertyKey.startsWith("__")) {
|
|
58
59
|
continue;
|
|
59
|
-
}
|
|
60
|
+
}
|
|
61
|
+
if (reservedPropertyKeys.includes(propertyKey)) {
|
|
60
62
|
continue;
|
|
61
63
|
}
|
|
62
64
|
properties.push(propertyKey);
|
|
@@ -64,7 +66,7 @@ class EntityController extends BaseController {
|
|
|
64
66
|
EntityController.entityPropertiesCache.set(entityClass, properties);
|
|
65
67
|
return properties;
|
|
66
68
|
}
|
|
67
|
-
options = /* @__PURE__ */ __name(async (
|
|
69
|
+
options = /* @__PURE__ */ __name(async (_request, reply) => {
|
|
68
70
|
try {
|
|
69
71
|
const EntityClass = await this.getEntity();
|
|
70
72
|
if (!EntityClass) {
|
|
@@ -82,7 +84,7 @@ class EntityController extends BaseController {
|
|
|
82
84
|
this.sendErrorResponse({ reply, error });
|
|
83
85
|
}
|
|
84
86
|
}, "options");
|
|
85
|
-
metadata = /* @__PURE__ */ __name(async (
|
|
87
|
+
metadata = /* @__PURE__ */ __name(async (_request, reply) => {
|
|
86
88
|
try {
|
|
87
89
|
const EntityClass = await this.getEntity();
|
|
88
90
|
if (!EntityClass) {
|
|
@@ -120,8 +122,8 @@ class EntityController extends BaseController {
|
|
|
120
122
|
this.sendErrorResponse({ reply, error: "Entity not found" });
|
|
121
123
|
return;
|
|
122
124
|
}
|
|
123
|
-
const page = parseInt(request.query.page) || 1;
|
|
124
|
-
const limit = parseInt(request.query.limit);
|
|
125
|
+
const page = parseInt(request.query.page, 10) || 1;
|
|
126
|
+
const limit = parseInt(request.query.limit, 10);
|
|
125
127
|
const offset = (page - 1) * (limit > 0 ? limit : 0);
|
|
126
128
|
const filters = request.query.filters ? JSON.parse(request.query.filters) : {};
|
|
127
129
|
const sortOrder = request.query["sort-order"] || "ASC";
|
|
@@ -131,7 +133,7 @@ class EntityController extends BaseController {
|
|
|
131
133
|
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
132
134
|
continue;
|
|
133
135
|
}
|
|
134
|
-
if (!Object.
|
|
136
|
+
if (!Object.hasOwn(request.query, key)) {
|
|
135
137
|
continue;
|
|
136
138
|
}
|
|
137
139
|
if (key.endsWith("[]")) {
|
|
@@ -158,7 +160,7 @@ class EntityController extends BaseController {
|
|
|
158
160
|
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
159
161
|
continue;
|
|
160
162
|
}
|
|
161
|
-
if (!Object.
|
|
163
|
+
if (!Object.hasOwn(normalizedQuery, key)) {
|
|
162
164
|
continue;
|
|
163
165
|
}
|
|
164
166
|
if (reservedQueryKeys.includes(key)) {
|
|
@@ -212,7 +214,7 @@ class EntityController extends BaseController {
|
|
|
212
214
|
});
|
|
213
215
|
}
|
|
214
216
|
const populate = request.query.populate ? request.query.populate.split(",") : [];
|
|
215
|
-
const [items, total] = await em.findAndCount(
|
|
217
|
+
const [items, total] = await em.findAndCount(EntityClass, options.filters, {
|
|
216
218
|
limit: options.limit,
|
|
217
219
|
offset: options.offset,
|
|
218
220
|
orderBy: options.orderBy,
|
|
@@ -264,7 +266,7 @@ class EntityController extends BaseController {
|
|
|
264
266
|
return;
|
|
265
267
|
}
|
|
266
268
|
const id = request.params.id;
|
|
267
|
-
const item = await em.findOne(
|
|
269
|
+
const item = await em.findOne(EntityClass, { id }, { populate });
|
|
268
270
|
if (!item) {
|
|
269
271
|
return this.sendNotFoundResponse(reply, `${EntityClass.singularNameCapitalized} not found`);
|
|
270
272
|
}
|
|
@@ -308,8 +310,8 @@ class EntityController extends BaseController {
|
|
|
308
310
|
if (error) {
|
|
309
311
|
return this.sendErrorResponse({ reply, error: error.message });
|
|
310
312
|
}
|
|
311
|
-
const item = em.create(
|
|
312
|
-
await em.
|
|
313
|
+
const item = em.create(EntityClass, value);
|
|
314
|
+
await em.persist(item).flush();
|
|
313
315
|
await this.postCreateOne({
|
|
314
316
|
entityManager: em,
|
|
315
317
|
request,
|
|
@@ -336,12 +338,12 @@ class EntityController extends BaseController {
|
|
|
336
338
|
if (error) {
|
|
337
339
|
return this.sendErrorResponse({ reply, error: error.message });
|
|
338
340
|
}
|
|
339
|
-
const item = await em.findOne(
|
|
341
|
+
const item = await em.findOne(EntityClass, { id });
|
|
340
342
|
if (!item) {
|
|
341
343
|
return this.sendNotFoundResponse(reply, `${EntityClass.singularNameCapitalized} not found`);
|
|
342
344
|
}
|
|
343
345
|
em.assign(item, value);
|
|
344
|
-
await em.
|
|
346
|
+
await em.persist(item).flush();
|
|
345
347
|
await this.postUpdateOne({
|
|
346
348
|
entityManager: em,
|
|
347
349
|
request,
|
|
@@ -362,11 +364,11 @@ class EntityController extends BaseController {
|
|
|
362
364
|
return;
|
|
363
365
|
}
|
|
364
366
|
const id = request.params.id;
|
|
365
|
-
const item = await em.findOne(
|
|
367
|
+
const item = await em.findOne(EntityClass, { id });
|
|
366
368
|
if (!item) {
|
|
367
369
|
return this.sendNotFoundResponse(reply, `${EntityClass.singularNameCapitalized} not found`);
|
|
368
370
|
}
|
|
369
|
-
await em.
|
|
371
|
+
await em.remove(item).flush();
|
|
370
372
|
reply.status(StatusCodes.NO_CONTENT).send();
|
|
371
373
|
} catch (error) {
|
|
372
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 // Cache for entity properties to avoid repeated prototype iteration\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 } else 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) || 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,YAAY,mCAA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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;AAEA,UAAM,mBAAmB,OAAO,QAAQ,MAAM,EAC3C,OAAO,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,EAAE,OAAO,EAC1C,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;AAEjB,UAAM,QAAQ,gBAAgB;AAE9B,QAAI,CAAC,OAAO;AACV,YAAM,KAAK,GAAG,EAAE,KAAK;AAAA,QACnB,OAAO;AAAA,QACP;AAAA,QACA;AAAA,QACA,UAAU,UAAU,eAAe,UAAU,oBAAoB;AAAA,QACjE,QAAQ;AAAA,QACR,qBAAqB;AAAA,MACvB,CAAC;AACD;AAAA,IACF;AAEA,UAAM,KAAK,EAAE,OAAO,MAAM,OAAO,QAAQ,qBAAqB,KAAK,CAAC;AAAA,EACtE,GA7Be;AA8BjB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { RouteSchemaDefinition } from './webserver.interface.js';
|
|
2
1
|
import type { ControllerAction } from './controller/base.interface.js';
|
|
2
|
+
import type { RouteSchemaDefinition } from './webserver.interface.js';
|
|
3
3
|
/**
|
|
4
4
|
* Define a typed controller action with schema inference.
|
|
5
5
|
* This helper provides TypeScript type inference for controller methods based on Zod schemas.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-action.d.ts","sourceRoot":"","sources":["../../src/webserver/define-action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"define-action.d.ts","sourceRoot":"","sources":["../../src/webserver/define-action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEtE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,MAAM,SAAS,qBAAqB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EACxF,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,gBAAgB,CAAC,MAAM,CAAC,GAChC,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAE5B;;;GAGG;AAEH,wBAAgB,YAAY,CAAC,MAAM,SAAS,SAAS,GAAG,SAAS,EAC/D,OAAO,EAAE,gBAAgB,CAAC,MAAM,CAAC,GAChC,gBAAgB,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/webserver/define-action.ts"],
|
|
4
|
-
"sourcesContent": ["import type {
|
|
4
|
+
"sourcesContent": ["import type { ControllerAction } from './controller/base.interface.js';\nimport type { RouteSchemaDefinition } from './webserver.interface.js';\n\n/**\n * Define a typed controller action with schema inference.\n * This helper provides TypeScript type inference for controller methods based on Zod schemas.\n *\n * @example\n * const helloSchema = {\n * body: z.object({ name: z.string() }),\n * response: { 200: z.object({ message: z.string() }) }\n * } satisfies RouteSchemaDefinition;\n *\n * class MyController extends WebServerBaseController {\n * hello = defineAction(helloSchema, async (request, reply) => {\n * // request.body is typed as { name: string }\n * return reply.send({ message: `Hello ${request.body.name}` });\n * });\n * }\n */\nexport function defineAction<Schema extends RouteSchemaDefinition<any, any, any, any, any>>(\n schema: Schema,\n handler: ControllerAction<Schema>,\n): ControllerAction<Schema>;\n\n/**\n * Define a controller action without a schema.\n * Useful for actions that don't need validation or type inference.\n */\n// eslint-disable-next-line no-redeclare\nexport function defineAction<Schema extends undefined = undefined>(\n handler: ControllerAction<Schema>,\n): ControllerAction<Schema>;\n\n// eslint-disable-next-line no-redeclare\nexport function defineAction<Schema extends RouteSchemaDefinition<any, any, any, any, any> | undefined>(\n schemaOrHandler: Schema | ControllerAction<Schema>,\n handler?: ControllerAction<Schema>,\n): ControllerAction<Schema> {\n if (typeof schemaOrHandler === 'function') {\n // No schema provided, just return the handler\n return schemaOrHandler;\n }\n\n // Schema provided, return the handler\n // Note: The schema is attached for documentation/IDE purposes only\n // Actual validation happens at the route level\n if (!handler) {\n throw new Error('Handler is required when schema is provided');\n }\n\n return handler;\n}\n"],
|
|
5
5
|
"mappings": ";;AAmCO,SAAS,aACd,iBACA,SAC0B;AAC1B,MAAI,OAAO,oBAAoB,YAAY;AAEzC,WAAO;AAAA,EACT;AAKA,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,6CAA6C;AAAA,EAC/D;AAEA,SAAO;AACT;AAjBgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { HTTPMethods } from 'fastify';
|
|
2
|
-
import { type RouteSchemaDefinition, type WebServerRoute } from './webserver.interface.js';
|
|
3
2
|
import type { ControllerAction, WebServerBaseControllerType } from './controller/base.interface.js';
|
|
3
|
+
import { type RouteSchemaDefinition, type WebServerRoute } from './webserver.interface.js';
|
|
4
4
|
export interface DefineRouteConfig<Schema extends RouteSchemaDefinition<any, any, any, any, any> | undefined, Handler extends ControllerAction<Schema>> {
|
|
5
5
|
method: HTTPMethods | HTTPMethods[];
|
|
6
6
|
path: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-route.d.ts","sourceRoot":"","sources":["../../src/webserver/define-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,
|
|
1
|
+
{"version":3,"file":"define-route.d.ts","sourceRoot":"","sources":["../../src/webserver/define-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AACpG,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EAEpB,MAAM,0BAA0B,CAAC;AAElC,MAAM,WAAW,iBAAiB,CAChC,MAAM,SAAS,qBA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
"sources": ["../../src/webserver/define-route.ts"],
|
|
4
|
-
"sourcesContent": ["import type { HTTPMethods } from 'fastify';\nimport {\n type AnyRouteSchemaDefinition,\n type RouteSchemaDefinition,\n type WebServerRoute,\n WebServerRouteType,\n} from './webserver.interface.js';\
|
|
5
|
-
"mappings": ";;
|
|
4
|
+
"sourcesContent": ["import type { HTTPMethods } from 'fastify';\nimport type { ControllerAction, WebServerBaseControllerType } from './controller/base.interface.js';\nimport {\n type AnyRouteSchemaDefinition,\n type RouteSchemaDefinition,\n type WebServerRoute,\n WebServerRouteType,\n} from './webserver.interface.js';\n\nexport interface DefineRouteConfig<\n Schema extends RouteSchemaDefinition<any, any, any, any, any> | undefined,\n Handler extends ControllerAction<Schema>,\n> {\n method: HTTPMethods | HTTPMethods[];\n path: string;\n schema?: Schema;\n handler: Handler;\n}\n\nexport interface DefineRouteWithControllerConfig<\n Schema extends RouteSchemaDefinition<any, any, any, any, any> | undefined = undefined,\n> {\n method: HTTPMethods | HTTPMethods[];\n path: string;\n schema?: Schema;\n controller: WebServerBaseControllerType;\n action: string;\n}\n\n/**\n * Define a route with an inline handler function.\n * Provides full type inference for request parameters based on the schema.\n *\n * @example\n * const helloSchema = {\n * body: z.object({ name: z.string() }),\n * response: { 200: z.object({ message: z.string() }) }\n * } satisfies RouteSchemaDefinition;\n *\n * defineRoute({\n * method: 'POST',\n * path: '/hello',\n * schema: helloSchema,\n * handler: async (request, reply) => {\n * // request.body is typed as { name: string }\n * return reply.send({ message: `Hello ${request.body.name}` });\n * }\n * });\n */\nexport function defineRoute<\n Schema extends RouteSchemaDefinition<any, any, any, any, any> | undefined,\n Handler extends ControllerAction<Schema>,\n>(config: DefineRouteConfig<Schema, Handler>): WebServerRoute;\n\n/**\n * Define a route with a controller and action method.\n * Note: Type inference for controller actions is limited. Consider using inline handlers for full type safety.\n *\n * @example\n * defineRoute({\n * method: 'POST',\n * path: '/hello',\n * controller: HelloController,\n * action: 'create',\n * schema: helloSchema\n * });\n */\n// eslint-disable-next-line no-redeclare\nexport function defineRoute<Schema extends RouteSchemaDefinition<any, any, any, any, any> | undefined = undefined>(\n config: DefineRouteWithControllerConfig<Schema>,\n): WebServerRoute;\n\n// eslint-disable-next-line no-redeclare\nexport function defineRoute<\n Schema extends RouteSchemaDefinition<any, any, any, any, any> | undefined,\n Handler extends ControllerAction<Schema>,\n>(config: DefineRouteConfig<Schema, Handler> | DefineRouteWithControllerConfig<Schema>): WebServerRoute {\n const route: WebServerRoute = {\n type: WebServerRouteType.Default,\n method: config.method,\n path: config.path,\n };\n\n if ('handler' in config) {\n route.handler = config.handler as ControllerAction<any>;\n } else if ('controller' in config && 'action' in config) {\n route.controller = config.controller;\n route.action = config.action;\n }\n\n if (config.schema) {\n route.schema = config.schema as AnyRouteSchemaDefinition;\n }\n\n return route;\n}\n\nexport type DefineRoute = typeof defineRoute;\n"],
|
|
5
|
+
"mappings": ";;AAEA;AAAA,EAIE;AAAA,OACK;AAkEA,SAAS,YAGd,QAAsG;AACtG,QAAM,QAAwB;AAAA,IAC5B,MAAM,mBAAmB;AAAA,IACzB,QAAQ,OAAO;AAAA,IACf,MAAM,OAAO;AAAA,EACf;AAEA,MAAI,aAAa,QAAQ;AACvB,UAAM,UAAU,OAAO;AAAA,EACzB,WAAW,gBAAgB,UAAU,YAAY,QAAQ;AACvD,UAAM,aAAa,OAAO;AAC1B,UAAM,SAAS,OAAO;AAAA,EACxB;AAEA,MAAI,OAAO,QAAQ;AACjB,UAAM,SAAS,OAAO;AAAA,EACxB;AAEA,SAAO;AACT;AAtBgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export
|
|
3
|
-
export { WebServerRouteType } from './webserver.interface.js';
|
|
4
|
-
export { default as WebServerBaseController } from './controller/base.js';
|
|
1
|
+
export type { AuthenticatedRequest, AuthenticatedRouteHandler, AuthenticatedUser, RouteHandler, } from './controller/auth-middleware.js';
|
|
2
|
+
export { withAuth } from './controller/auth-middleware.js';
|
|
5
3
|
export type { ControllerAction, ControllerRequest, WebServerBaseControllerConstructorParams, } from './controller/base.interface.js';
|
|
6
|
-
export { default as
|
|
4
|
+
export { default as WebServerBaseController } from './controller/base.js';
|
|
7
5
|
export { default as WebServerEntityController } from './controller/entity.js';
|
|
8
6
|
export { default as ExampleAuthController } from './controller/example-auth.js';
|
|
9
|
-
export { default as
|
|
10
|
-
export type { AuthenticatedUser, AuthenticatedRequest, AuthenticatedRouteHandler, RouteHandler, } from './controller/auth-middleware.js';
|
|
11
|
-
export { withAuth } from './controller/auth-middleware.js';
|
|
12
|
-
export { defineRoute } from './define-route.js';
|
|
7
|
+
export { default as WebServerHealthController } from './controller/health.js';
|
|
13
8
|
export { defineAction } from './define-action.js';
|
|
9
|
+
export { defineRoute } from './define-route.js';
|
|
10
|
+
export { default as RouteUtil } from './util.js';
|
|
11
|
+
export type { RouteHandler as TypedRouteHandler, RouteHandlerContext, RouteSchemaDefinition, WebServerConstructorParams, WebServerOptions, WebServerRoute, } from './webserver.interface.js';
|
|
12
|
+
export { WebServerRouteType } from './webserver.interface.js';
|
|
13
|
+
export { default as WebServer } from './webserver.js';
|
|
14
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/webserver/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/webserver/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,oBAAoB,EACpB,yBAAyB,EACzB,iBAAiB,EACjB,YAAY,GACb,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,wCAAwC,GACzC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,OAAO,IAAI,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAChF,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,WAAW,CAAC;AACjD,YAAY,EACV,YAAY,IAAI,iBAAiB,EACjC,mBAAmB,EACnB,qBAAqB,EACrB,0BAA0B,EAC1B,gBAAgB,EAChB,cAAc,GACf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/webserver/index.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { default as default2 } from "./webserver.js";
|
|
2
|
-
import { WebServerRouteType } from "./webserver.interface.js";
|
|
3
|
-
import { default as default3 } from "./controller/base.js";
|
|
4
|
-
import { default as default4 } from "./controller/health.js";
|
|
5
|
-
import { default as default5 } from "./controller/entity.js";
|
|
6
|
-
import { default as default6 } from "./controller/example-auth.js";
|
|
7
|
-
import { default as default7 } from "./util.js";
|
|
8
1
|
import { withAuth } from "./controller/auth-middleware.js";
|
|
9
|
-
import {
|
|
2
|
+
import { default as default2 } from "./controller/base.js";
|
|
3
|
+
import { default as default3 } from "./controller/entity.js";
|
|
4
|
+
import { default as default4 } from "./controller/example-auth.js";
|
|
5
|
+
import { default as default5 } from "./controller/health.js";
|
|
10
6
|
import { defineAction } from "./define-action.js";
|
|
7
|
+
import { defineRoute } from "./define-route.js";
|
|
8
|
+
import { default as default6 } from "./util.js";
|
|
9
|
+
import { WebServerRouteType } from "./webserver.interface.js";
|
|
10
|
+
import { default as default7 } from "./webserver.js";
|
|
11
11
|
export {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
default4 as ExampleAuthController,
|
|
13
|
+
default6 as RouteUtil,
|
|
14
|
+
default7 as WebServer,
|
|
15
|
+
default2 as WebServerBaseController,
|
|
16
|
+
default3 as WebServerEntityController,
|
|
17
|
+
default5 as WebServerHealthController,
|
|
18
18
|
WebServerRouteType,
|
|
19
19
|
defineAction,
|
|
20
20
|
defineRoute,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/webserver/index.ts"],
|
|
4
|
-
"sourcesContent": ["export {
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["export type {\n AuthenticatedRequest,\n AuthenticatedRouteHandler,\n AuthenticatedUser,\n RouteHandler,\n} from './controller/auth-middleware.js';\nexport { withAuth } from './controller/auth-middleware.js';\nexport type {\n ControllerAction,\n ControllerRequest,\n WebServerBaseControllerConstructorParams,\n} from './controller/base.interface.js';\nexport { default as WebServerBaseController } from './controller/base.js';\nexport { default as WebServerEntityController } from './controller/entity.js';\nexport { default as ExampleAuthController } from './controller/example-auth.js';\nexport { default as WebServerHealthController } from './controller/health.js';\nexport { defineAction } from './define-action.js';\nexport { defineRoute } from './define-route.js';\nexport { default as RouteUtil } from './util.js';\nexport type {\n RouteHandler as TypedRouteHandler,\n RouteHandlerContext,\n RouteSchemaDefinition,\n WebServerConstructorParams,\n WebServerOptions,\n WebServerRoute,\n} from './webserver.interface.js';\nexport { WebServerRouteType } from './webserver.interface.js';\nexport { default as WebServer } from './webserver.js';\n"],
|
|
5
|
+
"mappings": "AAMA,SAAS,gBAAgB;AAMzB,SAAoB,WAAXA,gBAA0C;AACnD,SAAoB,WAAXA,gBAA4C;AACrD,SAAoB,WAAXA,gBAAwC;AACjD,SAAoB,WAAXA,gBAA4C;AACrD,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,SAAoB,WAAXA,gBAA4B;AASrC,SAAS,0BAA0B;AACnC,SAAoB,WAAXA,gBAA4B;",
|
|
6
6
|
"names": ["default"]
|
|
7
7
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type FastifyInstance, type HTTPMethods } from 'fastify';
|
|
2
|
-
import { type AnyRouteSchemaDefinition, type WebServerConstructorParams } from './webserver.interface.js';
|
|
3
|
-
import type { ControllerAction } from './controller/base.interface.js';
|
|
4
|
-
import type { LifecycleManager } from '../lifecycle/lifecycle-manager.js';
|
|
5
2
|
import { type ZodTypeProvider } from 'fastify-type-provider-zod';
|
|
3
|
+
import type { LifecycleManager } from '../lifecycle/lifecycle-manager.js';
|
|
4
|
+
import type { ControllerAction } from './controller/base.interface.js';
|
|
5
|
+
import { type AnyRouteSchemaDefinition, type WebServerConstructorParams } from './webserver.interface.js';
|
|
6
6
|
declare module 'fastify' {
|
|
7
7
|
interface FastifyRequest {
|
|
8
8
|
startTime?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webserver.d.ts","sourceRoot":"","sources":["../../src/webserver/webserver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"webserver.d.ts","sourceRoot":"","sources":["../../src/webserver/webserver.ts"],"names":[],"mappings":"AAKA,OAAgB,EACd,KAAK,eAAe,EAIpB,KAAK,WAAW,EACjB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAyC,KAAK,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAKxG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAM1E,OAAO,KAAK,EAAE,gBAAgB,EAA+B,MAAM,gCAAgC,CAAC;AAEpG,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,0BAA0B,EAIhC,MAAM,0BAA0B,CAAC;AAElC,OAAO,QAAQ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QACzC,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,WAAW,CAAC,EAAE,wBAAwB,CAAC;QACvC,eAAe,CAAC,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC;KACzC,GAAG,OAAO,CAAC,IAAI,CAAC;IA2CjB;;OAEG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAanC;;OAEG;IACU,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAMlC,OAAO,CAAC,kBAAkB;IAgC1B;;OAEG;IACI,OAAO,IAAI,OAAO;IAIzB;;OAEG;IACI,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;CAGlE;AAED,eAAe,SAAS,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { FastifyReply, FastifyRequest, HTTPMethods, RouteGenericInterface } from 'fastify';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
import type { ApplicationConfig } from '../application/base-application.interface.js';
|
|
2
4
|
import type { DatabaseInstance } from '../database/index.js';
|
|
5
|
+
import type EventManager from '../event/manager.js';
|
|
6
|
+
import type { LifecycleManager } from '../lifecycle/lifecycle-manager.js';
|
|
3
7
|
import type { QueueManager } from '../queue/index.js';
|
|
4
8
|
import type { RedisInstance } from '../redis/index.js';
|
|
5
9
|
import type { ControllerAction, WebServerBaseControllerType } from './controller/base.interface.js';
|
|
6
|
-
import type { ApplicationConfig } from '../application/base-application.interface.js';
|
|
7
|
-
import type EventManager from '../event/manager.js';
|
|
8
|
-
import type { LifecycleManager } from '../lifecycle/lifecycle-manager.js';
|
|
9
|
-
import type { z } from 'zod';
|
|
10
10
|
export interface RouteSchemaDefinition<TParams extends z.ZodTypeAny | undefined = undefined, TQuery extends z.ZodTypeAny | undefined = undefined, TBody extends z.ZodTypeAny | undefined = undefined, TReply extends Record<number | `${number}`, z.ZodTypeAny> | undefined = undefined, THeaders extends z.ZodTypeAny | undefined = undefined> {
|
|
11
11
|
params?: TParams;
|
|
12
12
|
querystring?: TQuery;
|
|
@@ -24,7 +24,7 @@ export interface RouteHandlerContext<Schema extends RouteSchemaDefinition | unde
|
|
|
24
24
|
Reply?: Schema extends RouteSchemaDefinition<any, any, any, infer TReply, any> ? InferResponse<TReply> : RouteGenericInterface['Reply'];
|
|
25
25
|
}
|
|
26
26
|
export type AnyRouteSchemaDefinition = RouteSchemaDefinition<z.ZodTypeAny | undefined, z.ZodTypeAny | undefined, z.ZodTypeAny | undefined, Record<number | `${number}`, z.ZodTypeAny> | undefined, z.ZodTypeAny | undefined>;
|
|
27
|
-
export type RouteHandler<Schema extends RouteSchemaDefinition | undefined = undefined> = (request: FastifyRequest<RouteHandlerContext<Schema>>, reply: FastifyReply) => Promise<RouteHandlerContext<Schema>['Reply'] |
|
|
27
|
+
export type RouteHandler<Schema extends RouteSchemaDefinition | undefined = undefined> = (request: FastifyRequest<RouteHandlerContext<Schema>>, reply: FastifyReply) => Promise<RouteHandlerContext<Schema>['Reply'] | undefined> | RouteHandlerContext<Schema>['Reply'] | undefined;
|
|
28
28
|
export interface WebServerConstructorParams {
|
|
29
29
|
/** Application configuration */
|
|
30
30
|
applicationConfig: ApplicationConfig;
|