@scpxl/nodejs-framework 1.0.32 → 1.0.43
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/dist/application/base-application.d.ts +7 -7
- package/dist/application/base-application.d.ts.map +1 -1
- package/dist/application/base-application.interface.d.ts +1 -1
- package/dist/application/base-application.interface.d.ts.map +1 -1
- package/dist/application/base-application.js +114 -14
- package/dist/application/base-application.js.map +2 -2
- package/dist/application/web-application.d.ts.map +1 -1
- package/dist/application/web-application.js +2 -1
- package/dist/application/web-application.js.map +2 -2
- package/dist/cache/manager.d.ts +1 -0
- package/dist/cache/manager.d.ts.map +1 -1
- package/dist/cache/manager.js +11 -2
- package/dist/cache/manager.js.map +2 -2
- package/dist/cli/index.js +28 -12
- package/dist/cli/index.js.map +2 -2
- package/dist/config/schema.d.ts +2 -63
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +1 -7
- package/dist/config/schema.js.map +2 -2
- package/dist/event/manager.js +2 -2
- package/dist/event/manager.js.map +2 -2
- package/dist/logger/logger.js +0 -1
- package/dist/logger/logger.js.map +2 -2
- package/dist/queue/manager.d.ts.map +1 -1
- package/dist/queue/manager.js +19 -7
- package/dist/queue/manager.js.map +2 -2
- package/dist/redis/instance.d.ts.map +1 -1
- package/dist/redis/instance.js +9 -1
- package/dist/redis/instance.js.map +2 -2
- package/dist/redis/manager.d.ts.map +1 -1
- package/dist/redis/manager.js +26 -16
- package/dist/redis/manager.js.map +3 -3
- package/dist/webserver/controller/entity.js +1 -1
- package/dist/webserver/controller/entity.js.map +2 -2
- package/dist/webserver/controller/health.js.map +1 -1
- package/dist/webserver/util.d.ts +1 -1
- package/dist/webserver/util.d.ts.map +1 -1
- package/dist/webserver/util.js +5 -23
- package/dist/webserver/util.js.map +2 -2
- package/dist/webserver/webserver.d.ts +2 -13
- package/dist/webserver/webserver.d.ts.map +1 -1
- package/dist/webserver/webserver.interface.d.ts +1 -21
- package/dist/webserver/webserver.interface.d.ts.map +1 -1
- package/dist/webserver/webserver.interface.js.map +1 -1
- package/dist/webserver/webserver.js +34 -36
- package/dist/webserver/webserver.js.map +2 -2
- package/dist/websocket/define-subscriber.d.ts +8 -1
- package/dist/websocket/define-subscriber.d.ts.map +1 -1
- package/dist/websocket/define-subscriber.js +2 -1
- package/dist/websocket/define-subscriber.js.map +2 -2
- package/dist/websocket/index.d.ts +4 -0
- package/dist/websocket/index.d.ts.map +1 -1
- package/dist/websocket/index.js +43 -1
- package/dist/websocket/index.js.map +2 -2
- package/dist/websocket/subscriber-middleware.d.ts +52 -0
- package/dist/websocket/subscriber-middleware.d.ts.map +1 -0
- package/dist/websocket/subscriber-middleware.js +200 -0
- package/dist/websocket/subscriber-middleware.js.map +7 -0
- package/dist/websocket/subscriber-utils.d.ts +88 -0
- package/dist/websocket/subscriber-utils.d.ts.map +1 -0
- package/dist/websocket/subscriber-utils.js +227 -0
- package/dist/websocket/subscriber-utils.js.map +7 -0
- package/dist/websocket/utils.d.ts.map +1 -1
- package/dist/websocket/utils.js +5 -1
- package/dist/websocket/utils.js.map +2 -2
- package/dist/websocket/websocket-base.d.ts.map +1 -1
- package/dist/websocket/websocket-base.js +9 -1
- package/dist/websocket/websocket-base.js.map +2 -2
- package/dist/websocket/websocket-server.d.ts +41 -1
- package/dist/websocket/websocket-server.d.ts.map +1 -1
- package/dist/websocket/websocket-server.js +90 -7
- package/dist/websocket/websocket-server.js.map +2 -2
- package/dist/websocket/websocket.interface.d.ts +7 -0
- package/dist/websocket/websocket.interface.d.ts.map +1 -1
- package/dist/websocket/websocket.interface.js.map +2 -2
- package/package.json +5 -6
package/dist/redis/manager.js
CHANGED
|
@@ -136,34 +136,44 @@ class RedisManager {
|
|
|
136
136
|
host: this.options.host,
|
|
137
137
|
port: this.options.port,
|
|
138
138
|
password: this.options.password,
|
|
139
|
-
maxRetriesPerRequest: null
|
|
139
|
+
maxRetriesPerRequest: null,
|
|
140
140
|
// Needed for bullmq
|
|
141
|
+
lazyConnect: true
|
|
142
|
+
// Prevent automatic connection to avoid unhandled errors
|
|
141
143
|
};
|
|
142
144
|
const useInMemoryRedis = truthyPattern.test(process.env.PXL_REDIS_IN_MEMORY ?? "") || truthyPattern.test(process.env.REDIS_IN_MEMORY ?? "");
|
|
143
145
|
const createClient = /* @__PURE__ */ __name(() => {
|
|
144
146
|
if (useInMemoryRedis) {
|
|
145
147
|
return new InMemoryRedisClient(getGlobalInMemoryRedisState());
|
|
146
148
|
}
|
|
147
|
-
|
|
149
|
+
const client2 = new Redis(redisOptions);
|
|
150
|
+
const errorHandler = /* @__PURE__ */ __name((error) => {
|
|
151
|
+
}, "errorHandler");
|
|
152
|
+
client2.once("error", errorHandler);
|
|
153
|
+
return client2;
|
|
148
154
|
}, "createClient");
|
|
149
155
|
const client = createClient();
|
|
150
156
|
const publisherClient = createClient();
|
|
151
157
|
const subscriberClient = createClient();
|
|
152
158
|
try {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
159
|
+
if (!useInMemoryRedis) {
|
|
160
|
+
await Promise.all([client.connect(), publisherClient.connect(), subscriberClient.connect()]);
|
|
161
|
+
} else {
|
|
162
|
+
await Promise.all([
|
|
163
|
+
new Promise((resolve, reject) => {
|
|
164
|
+
client.once("ready", () => resolve());
|
|
165
|
+
client.once("error", (error) => reject(error));
|
|
166
|
+
}),
|
|
167
|
+
new Promise((resolve, reject) => {
|
|
168
|
+
publisherClient.once("ready", () => resolve());
|
|
169
|
+
publisherClient.once("error", (error) => reject(error));
|
|
170
|
+
}),
|
|
171
|
+
new Promise((resolve, reject) => {
|
|
172
|
+
subscriberClient.once("ready", () => resolve());
|
|
173
|
+
subscriberClient.once("error", (error) => reject(error));
|
|
174
|
+
})
|
|
175
|
+
]);
|
|
176
|
+
}
|
|
167
177
|
const redisInstance = new RedisInstance({
|
|
168
178
|
redisManager: this,
|
|
169
179
|
client,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/redis/manager.ts"],
|
|
4
|
-
"sourcesContent": ["import { Redis, type RedisOptions } from 'ioredis';\nimport { EventEmitter } from 'node:events';\nimport type { RedisManagerConfig as RedisManagerOptions } from './manager.interface.js';\nimport RedisInstance from './instance.js';\nimport { Logger } from '../logger/index.js';\nimport { CachePerformanceWrapper } from '../performance/index.js';\nimport { safeSerializeError } from '../error/error-reporter.js';\n\nconst truthyPattern = /^(1|true|yes|on)$/i;\nconst scheduleMicrotask =\n typeof (globalThis as any).queueMicrotask === 'function'\n ? (globalThis as any).queueMicrotask.bind(globalThis)\n : (callback: () => void) => {\n void Promise.resolve().then(callback);\n };\n\ntype RedisCallback = (error: Error | null, result?: string) => void;\n\ninterface InMemoryRedisSharedState {\n store: Map<string, string | Buffer>;\n expirations: Map<string, NodeJS.Timeout>;\n subscriptions: Map<string, Set<InMemoryRedisClient>>;\n}\n\n// Global singleton shared state for in-memory Redis\nlet globalInMemoryRedisState: InMemoryRedisSharedState | null = null;\n\nfunction getGlobalInMemoryRedisState(): InMemoryRedisSharedState {\n globalInMemoryRedisState ??= {\n store: new Map<string, string | Buffer>(),\n expirations: new Map<string, NodeJS.Timeout>(),\n subscriptions: new Map<string, Set<InMemoryRedisClient>>(),\n };\n return globalInMemoryRedisState;\n}\n\nclass InMemoryRedisClient extends EventEmitter {\n private shared: InMemoryRedisSharedState;\n\n constructor(shared: InMemoryRedisSharedState) {\n super();\n this.shared = shared;\n\n scheduleMicrotask(() => {\n this.emit('ready');\n });\n }\n\n private cleanupSubscriptions(): void {\n for (const subscribers of this.shared.subscriptions.values()) {\n subscribers.delete(this);\n }\n }\n\n private clearExpirationForKey(key: string): void {\n const timer = this.shared.expirations.get(key);\n if (timer) {\n clearTimeout(timer);\n this.shared.expirations.delete(key);\n }\n }\n\n public ping(callback?: RedisCallback): Promise<string> {\n if (callback) {\n callback(null, 'PONG');\n return Promise.resolve('PONG');\n }\n\n return Promise.resolve('PONG');\n }\n\n public async set(...args: any[]): Promise<'OK'> {\n const [key, value, mode, expiration] = args;\n const serializedValue: string | Buffer = value instanceof Buffer ? value : String(value);\n\n this.shared.store.set(key, serializedValue);\n this.clearExpirationForKey(key);\n\n if (typeof mode === 'string' && mode.toUpperCase() === 'EX' && typeof expiration === 'number') {\n const timer = setTimeout(() => {\n this.shared.store.delete(key);\n this.shared.expirations.delete(key);\n }, expiration * 1000);\n\n if (typeof timer.unref === 'function') {\n timer.unref();\n }\n\n this.shared.expirations.set(key, timer);\n }\n\n return 'OK';\n }\n\n public async get(key: string): Promise<string | null> {\n return (this.shared.store.get(key) as string | undefined) ?? null;\n }\n\n public async del(key: string): Promise<number> {\n const existed = this.shared.store.delete(key);\n this.clearExpirationForKey(key);\n return existed ? 1 : 0;\n }\n\n public async publish(channel: string, message: string): Promise<number> {\n const subscribers = this.shared.subscriptions.get(channel);\n\n if (!subscribers || subscribers.size === 0) {\n return 0;\n }\n\n for (const subscriber of subscribers) {\n scheduleMicrotask(() => {\n subscriber.emit('message', channel, message);\n });\n }\n\n return subscribers.size;\n }\n\n public async subscribe(channel: string): Promise<number> {\n let subscribers = this.shared.subscriptions.get(channel);\n if (!subscribers) {\n subscribers = new Set<InMemoryRedisClient>();\n this.shared.subscriptions.set(channel, subscribers);\n }\n subscribers.add(this);\n return subscribers.size;\n }\n\n public async unsubscribe(channel: string): Promise<number> {\n const subscribers = this.shared.subscriptions.get(channel);\n\n if (!subscribers) {\n return 0;\n }\n\n subscribers.delete(this);\n return subscribers.size;\n }\n\n public async quit(): Promise<'OK'> {\n this.cleanupSubscriptions();\n this.emit('end');\n this.removeAllListeners();\n return 'OK';\n }\n\n public disconnect(): void {\n this.cleanupSubscriptions();\n this.emit('end');\n this.removeAllListeners();\n }\n}\n\nexport default class RedisManager {\n private logger: typeof Logger = Logger;\n\n private options: RedisManagerOptions;\n\n public instances: RedisInstance[] = [];\n\n constructor(config: RedisManagerOptions) {\n this.options = config;\n }\n\n public async connect(): Promise<RedisInstance> {\n return CachePerformanceWrapper.monitorConnection(\n 'connect',\n async () => {\n const startTime = performance.now();\n\n const redisOptions: RedisOptions = {\n host: this.options.host,\n port: this.options.port,\n password: this.options.password,\n maxRetriesPerRequest: null, // Needed for bullmq\n };\n\n const useInMemoryRedis =\n truthyPattern.test(process.env.PXL_REDIS_IN_MEMORY ?? '') ||\n truthyPattern.test(process.env.REDIS_IN_MEMORY ?? '');\n\n const createClient = (): Redis => {\n if (useInMemoryRedis) {\n return new InMemoryRedisClient(getGlobalInMemoryRedisState()) as unknown as Redis;\n }\n\n return new Redis(redisOptions);\n };\n\n const client = createClient();\n const publisherClient = createClient();\n const subscriberClient = createClient();\n\n try {\n // Wait for all three clients to be ready\n await Promise.all([\n new Promise<void>((resolve, reject) => {\n client.once('ready', () => resolve());\n client.once('error', (error: Error) => reject(error));\n }),\n new Promise<void>((resolve, reject) => {\n publisherClient.once('ready', () => resolve());\n publisherClient.once('error', (error: Error) => reject(error));\n }),\n new Promise<void>((resolve, reject) => {\n subscriberClient.once('ready', () => resolve());\n subscriberClient.once('error', (error: Error) => reject(error));\n }),\n ]);\n\n const redisInstance = new RedisInstance({\n redisManager: this,\n client,\n publisherClient,\n subscriberClient,\n });\n\n this.instances.push(redisInstance);\n\n const duration = performance.now() - startTime;\n const meta = {\n Host: this.options.host,\n Port: this.options.port,\n Duration: `${duration.toFixed(2)}ms`,\n Mode: useInMemoryRedis ? 'in-memory' : 'network',\n };\n\n if (this.options.applicationConfig.log?.startUp) {\n this.log('Connected', meta);\n } else {\n this.logger.debug({ message: 'Redis connected', meta });\n }\n\n if (useInMemoryRedis) {\n this.logger.debug({ message: 'Using in-memory Redis stub' });\n }\n\n return redisInstance;\n } catch (error) {\n const duration = performance.now() - startTime;\n\n // Clean up clients on error\n await Promise.allSettled([client.quit(), publisherClient.quit(), subscriberClient.quit()]);\n\n this.logger.error({\n error: error instanceof Error ? error : new Error(safeSerializeError(error)),\n message: 'Redis connection failed',\n meta: {\n Host: this.options.host,\n Port: this.options.port,\n Duration: `${duration.toFixed(2)}ms`,\n Mode: useInMemoryRedis ? 'in-memory' : 'network',\n },\n });\n\n throw error;\n }\n },\n { host: this.options.host, port: this.options.port },\n );\n }\n\n public async disconnect(): Promise<void> {\n await CachePerformanceWrapper.monitorConnection(\n 'disconnect',\n async () => {\n const startTime = performance.now();\n const instanceCount = this.instances.length;\n\n try {\n await Promise.all(this.instances.map(instance => instance.disconnect()));\n\n const duration = performance.now() - startTime;\n\n if (instanceCount > 0) {\n const meta = {\n Instances: instanceCount,\n Host: this.options.host,\n Port: this.options.port,\n Duration: `${duration.toFixed(2)}ms`,\n };\n\n if (this.options.applicationConfig.log?.startUp) {\n this.log('Disconnected all Redis instances', meta);\n } else {\n this.logger.debug({ message: 'Redis instances disconnected', meta });\n }\n }\n\n this.instances = [];\n } catch (error) {\n const duration = performance.now() - startTime;\n\n this.logger.error({\n error: error instanceof Error ? error : new Error(safeSerializeError(error)),\n message: 'Redis disconnection failed',\n meta: {\n Host: this.options.host,\n Port: this.options.port,\n Instances: instanceCount,\n Duration: `${duration.toFixed(2)}ms`,\n },\n });\n\n throw error;\n }\n },\n { host: this.options.host, port: this.options.port },\n );\n }\n\n /**\n * Log Redis message\n */\n public log(message: string, meta?: Record<string, unknown>): void {\n this.logger.custom({ level: 'redis', message, meta });\n }\n}\n"],
|
|
5
|
-
"mappings": ";;AAAA,SAAS,aAAgC;AACzC,SAAS,oBAAoB;AAE7B,OAAO,mBAAmB;AAC1B,SAAS,cAAc;AACvB,SAAS,+BAA+B;AACxC,SAAS,0BAA0B;AAEnC,MAAM,gBAAgB;AACtB,MAAM,oBACJ,OAAQ,WAAmB,mBAAmB,aACzC,WAAmB,eAAe,KAAK,UAAU,IAClD,CAAC,aAAyB;AACxB,OAAK,QAAQ,QAAQ,EA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,SAAK,mBAAmB;AACxB,WAAO;AAAA,EACT;AAAA,EAEO,aAAmB;AACxB,SAAK,qBAAqB;AAC1B,SAAK,KAAK,KAAK;AACf,SAAK,mBAAmB;AAAA,EAC1B;AACF;AAEA,MAAO,aAA2B;AAAA,EA3JlC,OA2JkC;AAAA;AAAA;AAAA,EACxB,SAAwB;AAAA,EAExB;AAAA,EAED,YAA6B,CAAC;AAAA,EAErC,YAAY,QAA6B;AACvC,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAa,UAAkC;AAC7C,WAAO,wBAAwB;AAAA,MAC7B;AAAA,MACA,YAAY;AACV,cAAM,YAAY,YAAY,IAAI;AAElC,cAAM,eAA6B;AAAA,UACjC,MAAM,KAAK,QAAQ;AAAA,UACnB,MAAM,KAAK,QAAQ;AAAA,UACnB,UAAU,KAAK,QAAQ;AAAA,UACvB,sBAAsB;AAAA;AAAA,
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import { Redis, type RedisOptions } from 'ioredis';\nimport { EventEmitter } from 'node:events';\nimport type { RedisManagerConfig as RedisManagerOptions } from './manager.interface.js';\nimport RedisInstance from './instance.js';\nimport { Logger } from '../logger/index.js';\nimport { CachePerformanceWrapper } from '../performance/index.js';\nimport { safeSerializeError } from '../error/error-reporter.js';\n\nconst truthyPattern = /^(1|true|yes|on)$/i;\nconst scheduleMicrotask =\n typeof (globalThis as any).queueMicrotask === 'function'\n ? (globalThis as any).queueMicrotask.bind(globalThis)\n : (callback: () => void) => {\n void Promise.resolve().then(callback);\n };\n\ntype RedisCallback = (error: Error | null, result?: string) => void;\n\ninterface InMemoryRedisSharedState {\n store: Map<string, string | Buffer>;\n expirations: Map<string, NodeJS.Timeout>;\n subscriptions: Map<string, Set<InMemoryRedisClient>>;\n}\n\n// Global singleton shared state for in-memory Redis\nlet globalInMemoryRedisState: InMemoryRedisSharedState | null = null;\n\nfunction getGlobalInMemoryRedisState(): InMemoryRedisSharedState {\n globalInMemoryRedisState ??= {\n store: new Map<string, string | Buffer>(),\n expirations: new Map<string, NodeJS.Timeout>(),\n subscriptions: new Map<string, Set<InMemoryRedisClient>>(),\n };\n return globalInMemoryRedisState;\n}\n\nclass InMemoryRedisClient extends EventEmitter {\n private shared: InMemoryRedisSharedState;\n\n constructor(shared: InMemoryRedisSharedState) {\n super();\n this.shared = shared;\n\n scheduleMicrotask(() => {\n this.emit('ready');\n });\n }\n\n private cleanupSubscriptions(): void {\n for (const subscribers of this.shared.subscriptions.values()) {\n subscribers.delete(this);\n }\n }\n\n private clearExpirationForKey(key: string): void {\n const timer = this.shared.expirations.get(key);\n if (timer) {\n clearTimeout(timer);\n this.shared.expirations.delete(key);\n }\n }\n\n public ping(callback?: RedisCallback): Promise<string> {\n if (callback) {\n callback(null, 'PONG');\n return Promise.resolve('PONG');\n }\n\n return Promise.resolve('PONG');\n }\n\n public async set(...args: any[]): Promise<'OK'> {\n const [key, value, mode, expiration] = args;\n const serializedValue: string | Buffer = value instanceof Buffer ? value : String(value);\n\n this.shared.store.set(key, serializedValue);\n this.clearExpirationForKey(key);\n\n if (typeof mode === 'string' && mode.toUpperCase() === 'EX' && typeof expiration === 'number') {\n const timer = setTimeout(() => {\n this.shared.store.delete(key);\n this.shared.expirations.delete(key);\n }, expiration * 1000);\n\n if (typeof timer.unref === 'function') {\n timer.unref();\n }\n\n this.shared.expirations.set(key, timer);\n }\n\n return 'OK';\n }\n\n public async get(key: string): Promise<string | null> {\n return (this.shared.store.get(key) as string | undefined) ?? null;\n }\n\n public async del(key: string): Promise<number> {\n const existed = this.shared.store.delete(key);\n this.clearExpirationForKey(key);\n return existed ? 1 : 0;\n }\n\n public async publish(channel: string, message: string): Promise<number> {\n const subscribers = this.shared.subscriptions.get(channel);\n\n if (!subscribers || subscribers.size === 0) {\n return 0;\n }\n\n for (const subscriber of subscribers) {\n scheduleMicrotask(() => {\n subscriber.emit('message', channel, message);\n });\n }\n\n return subscribers.size;\n }\n\n public async subscribe(channel: string): Promise<number> {\n let subscribers = this.shared.subscriptions.get(channel);\n if (!subscribers) {\n subscribers = new Set<InMemoryRedisClient>();\n this.shared.subscriptions.set(channel, subscribers);\n }\n subscribers.add(this);\n return subscribers.size;\n }\n\n public async unsubscribe(channel: string): Promise<number> {\n const subscribers = this.shared.subscriptions.get(channel);\n\n if (!subscribers) {\n return 0;\n }\n\n subscribers.delete(this);\n return subscribers.size;\n }\n\n public async quit(): Promise<'OK'> {\n this.cleanupSubscriptions();\n this.emit('end');\n this.removeAllListeners();\n return 'OK';\n }\n\n public disconnect(): void {\n this.cleanupSubscriptions();\n this.emit('end');\n this.removeAllListeners();\n }\n}\n\nexport default class RedisManager {\n private logger: typeof Logger = Logger;\n\n private options: RedisManagerOptions;\n\n public instances: RedisInstance[] = [];\n\n constructor(config: RedisManagerOptions) {\n this.options = config;\n }\n\n public async connect(): Promise<RedisInstance> {\n return CachePerformanceWrapper.monitorConnection(\n 'connect',\n async () => {\n const startTime = performance.now();\n\n const redisOptions: RedisOptions = {\n host: this.options.host,\n port: this.options.port,\n password: this.options.password,\n maxRetriesPerRequest: null, // Needed for bullmq\n lazyConnect: true, // Prevent automatic connection to avoid unhandled errors\n };\n\n const useInMemoryRedis =\n truthyPattern.test(process.env.PXL_REDIS_IN_MEMORY ?? '') ||\n truthyPattern.test(process.env.REDIS_IN_MEMORY ?? '');\n\n const createClient = (): Redis => {\n if (useInMemoryRedis) {\n return new InMemoryRedisClient(getGlobalInMemoryRedisState()) as unknown as Redis;\n }\n\n const client = new Redis(redisOptions);\n // Attach a temporary error handler to prevent unhandled errors during connection\n const errorHandler = (error: Error) => {\n // Error will be handled by the promise rejection below\n };\n client.once('error', errorHandler);\n return client;\n };\n\n const client = createClient();\n const publisherClient = createClient();\n const subscriberClient = createClient();\n\n try {\n // For non-in-memory clients, explicitly connect since we use lazyConnect\n if (!useInMemoryRedis) {\n await Promise.all([client.connect(), publisherClient.connect(), subscriberClient.connect()]);\n } else {\n // Wait for in-memory clients to be ready\n await Promise.all([\n new Promise<void>((resolve, reject) => {\n client.once('ready', () => resolve());\n client.once('error', (error: Error) => reject(error));\n }),\n new Promise<void>((resolve, reject) => {\n publisherClient.once('ready', () => resolve());\n publisherClient.once('error', (error: Error) => reject(error));\n }),\n new Promise<void>((resolve, reject) => {\n subscriberClient.once('ready', () => resolve());\n subscriberClient.once('error', (error: Error) => reject(error));\n }),\n ]);\n }\n\n const redisInstance = new RedisInstance({\n redisManager: this,\n client,\n publisherClient,\n subscriberClient,\n });\n\n this.instances.push(redisInstance);\n\n const duration = performance.now() - startTime;\n const meta = {\n Host: this.options.host,\n Port: this.options.port,\n Duration: `${duration.toFixed(2)}ms`,\n Mode: useInMemoryRedis ? 'in-memory' : 'network',\n };\n\n if (this.options.applicationConfig.log?.startUp) {\n this.log('Connected', meta);\n } else {\n this.logger.debug({ message: 'Redis connected', meta });\n }\n\n if (useInMemoryRedis) {\n this.logger.debug({ message: 'Using in-memory Redis stub' });\n }\n\n return redisInstance;\n } catch (error) {\n const duration = performance.now() - startTime;\n\n // Clean up clients on error\n await Promise.allSettled([client.quit(), publisherClient.quit(), subscriberClient.quit()]);\n\n this.logger.error({\n error: error instanceof Error ? error : new Error(safeSerializeError(error)),\n message: 'Redis connection failed',\n meta: {\n Host: this.options.host,\n Port: this.options.port,\n Duration: `${duration.toFixed(2)}ms`,\n Mode: useInMemoryRedis ? 'in-memory' : 'network',\n },\n });\n\n throw error;\n }\n },\n { host: this.options.host, port: this.options.port },\n );\n }\n\n public async disconnect(): Promise<void> {\n await CachePerformanceWrapper.monitorConnection(\n 'disconnect',\n async () => {\n const startTime = performance.now();\n const instanceCount = this.instances.length;\n\n try {\n await Promise.all(this.instances.map(instance => instance.disconnect()));\n\n const duration = performance.now() - startTime;\n\n if (instanceCount > 0) {\n const meta = {\n Instances: instanceCount,\n Host: this.options.host,\n Port: this.options.port,\n Duration: `${duration.toFixed(2)}ms`,\n };\n\n if (this.options.applicationConfig.log?.startUp) {\n this.log('Disconnected all Redis instances', meta);\n } else {\n this.logger.debug({ message: 'Redis instances disconnected', meta });\n }\n }\n\n this.instances = [];\n } catch (error) {\n const duration = performance.now() - startTime;\n\n this.logger.error({\n error: error instanceof Error ? error : new Error(safeSerializeError(error)),\n message: 'Redis disconnection failed',\n meta: {\n Host: this.options.host,\n Port: this.options.port,\n Instances: instanceCount,\n Duration: `${duration.toFixed(2)}ms`,\n },\n });\n\n throw error;\n }\n },\n { host: this.options.host, port: this.options.port },\n );\n }\n\n /**\n * Log Redis message\n */\n public log(message: string, meta?: Record<string, unknown>): void {\n this.logger.custom({ level: 'redis', message, meta });\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA,SAAS,aAAgC;AACzC,SAAS,oBAAoB;AAE7B,OAAO,mBAAmB;AAC1B,SAAS,cAAc;AACvB,SAAS,+BAA+B;AACxC,SAAS,0BAA0B;AAEnC,MAAM,gBAAgB;AACtB,MAAM,oBACJ,OAAQ,WAAmB,mBAAmB,aACzC,WAAmB,eAAe,KAAK,UAAU,IAClD,CAAC,aAAyB;AACxB,OAAK,QAAQ,QAAQ,EAAE,KAAK,QAAQ;AACtC;AAWN,IAAI,2BAA4D;AAEhE,SAAS,8BAAwD;AAC/D,+BAA6B;AAAA,IAC3B,OAAO,oBAAI,IAA6B;AAAA,IACxC,aAAa,oBAAI,IAA4B;AAAA,IAC7C,eAAe,oBAAI,IAAsC;AAAA,EAC3D;AACA,SAAO;AACT;AAPS;AAST,MAAM,4BAA4B,aAAa;AAAA,EApC/C,OAoC+C;AAAA;AAAA;AAAA,EACrC;AAAA,EAER,YAAY,QAAkC;AAC5C,UAAM;AACN,SAAK,SAAS;AAEd,sBAAkB,MAAM;AACtB,WAAK,KAAK,OAAO;AAAA,IACnB,CAAC;AAAA,EACH;AAAA,EAEQ,uBAA6B;AACnC,eAAW,eAAe,KAAK,OAAO,cAAc,OAAO,GAAG;AAC5D,kBAAY,OAAO,IAAI;AAAA,IACzB;AAAA,EACF;AAAA,EAEQ,sBAAsB,KAAmB;AAC/C,UAAM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
|
|
19
19
|
this.entityManager = databaseInstance.getEntityManager();
|
|
20
20
|
}
|
|
21
21
|
getEntity = /* @__PURE__ */ __name(async () => {
|
|
22
|
-
if (
|
|
22
|
+
if (this.applicationConfig.database?.enabled !== true) {
|
|
23
23
|
throw new Error(`Database not enabled (Entity: ${this.entityName})`);
|
|
24
24
|
}
|
|
25
25
|
const cacheKey = `${this.applicationConfig.database.entitiesDirectory}:${this.entityName}`;
|
|
@@ -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';\nimport type { WebServerBaseControllerConstructorParams } from './base.interface.js';\n\nexport default abstract class EntityController extends BaseController {\n protected abstract entityName: string;\n\n protected entityManager: EntityManager;\n\n // Cache for entity modules to avoid repeated dynamic imports\n private static entityCache = new Map<string, typeof DynamicEntity>();\n\n constructor(props: WebServerBaseControllerConstructorParams) {\n super(props);\n\n const { databaseInstance } = props;\n\n this.entityManager = databaseInstance.getEntityManager();\n }\n\n protected getEntity = async (): Promise<typeof DynamicEntity | undefined> => {\n if (!this.applicationConfig.database || 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 // Call preGetMany hook\n await this.preGetMany({\n entityManager: this.entityManager,\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 this.entityManager.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: this.entityManager,\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 await this.preGetOne({\n entityManager: this.entityManager,\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 this.entityManager.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: this.entityManager,\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 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 = this.entityManager.create(this.entityName, value as object);\n\n await this.entityManager.persistAndFlush(item);\n\n // Call postCreateOne hook\n await this.postCreateOne({\n entityManager: this.entityManager,\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 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 this.entityManager.findOne(this.entityName, { id });\n\n if (!item) {\n return this.sendNotFoundResponse(reply, `${EntityClass.singularNameCapitalized} not found`);\n }\n\n this.entityManager.assign(item, value as object);\n\n await this.entityManager.persistAndFlush(item);\n\n // Call postUpdateOne hook\n await this.postUpdateOne({\n entityManager: this.entityManager,\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 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 this.entityManager.findOne(this.entityName, { id });\n\n if (!item) {\n return this.sendNotFoundResponse(reply, `${EntityClass.singularNameCapitalized} not found`);\n }\n\n await this.entityManager.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;AAC5B,OAAO,oBAAoB;AAE3B,SAAS,0BAA0B;AACnC,SAAS,cAAc;AAGvB,MAAO,yBAAgD,eAAe;AAAA,EAXtE,OAWsE;AAAA;AAAA;AAAA,EAG1D;AAAA;AAAA,EAGV,OAAe,cAAc,oBAAI,IAAkC;AAAA,EAEnE,YAAY,OAAiD;AAC3D,UAAM,KAAK;AAEX,UAAM,EAAE,iBAAiB,IAAI;AAE7B,SAAK,gBAAgB,iBAAiB,iBAAiB;AAAA,EACzD;AAAA,EAEU,YAAY,mCAAuD;AAC3E,QAAI,
|
|
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';\nimport type { WebServerBaseControllerConstructorParams } from './base.interface.js';\n\nexport default abstract class EntityController extends BaseController {\n protected abstract entityName: string;\n\n protected entityManager: EntityManager;\n\n // Cache for entity modules to avoid repeated dynamic imports\n private static entityCache = new Map<string, typeof DynamicEntity>();\n\n constructor(props: WebServerBaseControllerConstructorParams) {\n super(props);\n\n const { databaseInstance } = props;\n\n this.entityManager = databaseInstance.getEntityManager();\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 // Call preGetMany hook\n await this.preGetMany({\n entityManager: this.entityManager,\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 this.entityManager.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: this.entityManager,\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 await this.preGetOne({\n entityManager: this.entityManager,\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 this.entityManager.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: this.entityManager,\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 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 = this.entityManager.create(this.entityName, value as object);\n\n await this.entityManager.persistAndFlush(item);\n\n // Call postCreateOne hook\n await this.postCreateOne({\n entityManager: this.entityManager,\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 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 this.entityManager.findOne(this.entityName, { id });\n\n if (!item) {\n return this.sendNotFoundResponse(reply, `${EntityClass.singularNameCapitalized} not found`);\n }\n\n this.entityManager.assign(item, value as object);\n\n await this.entityManager.persistAndFlush(item);\n\n // Call postUpdateOne hook\n await this.postUpdateOne({\n entityManager: this.entityManager,\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 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 this.entityManager.findOne(this.entityName, { id });\n\n if (!item) {\n return this.sendNotFoundResponse(reply, `${EntityClass.singularNameCapitalized} not found`);\n }\n\n await this.entityManager.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;AAC5B,OAAO,oBAAoB;AAE3B,SAAS,0BAA0B;AACnC,SAAS,cAAc;AAGvB,MAAO,yBAAgD,eAAe;AAAA,EAXtE,OAWsE;AAAA;AAAA;AAAA,EAG1D;AAAA;AAAA,EAGV,OAAe,cAAc,oBAAI,IAAkC;AAAA,EAEnE,YAAY,OAAiD;AAC3D,UAAM,KAAK;AAEX,UAAM,EAAE,iBAAiB,IAAI;AAE7B,SAAK,gBAAgB,iBAAiB,iBAAiB;AAAA,EACzD;AAAA,EAEU,YAAY,mCAAuD;AAC3E,QAAI,KAAK,kBAAkB,UAAU,YAAY,MAAM;AACrD,YAAM,IAAI,MAAM,iCAAiC,KAAK,UAAU,GAAG;AAAA,IACrE;AAGA,UAAM,WAAW,GAAG,KAAK,kBAAkB,SAAS,iBAAiB,IAAI,KAAK,UAAU;AACxF,QAAI,iBAAiB,YAAY,IAAI,QAAQ,GAAG;AAC9C,aAAO,iBAAiB,YAAY,IAAI,QAAQ;AAAA,IAClD;AAGA,UAAM,mBAAm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AEA,YAAM,KAAK,QAAQ,OAAO;AAE1B,YAAM,OAAO,MAAM,KAAK,cAAc,QAAQ,KAAK,YAAY,EAAE,GAAG,CAAC;AAErE,UAAI,CAAC,MAAM;AACT,eAAO,KAAK,qBAAqB,OAAO,GAAG,YAAY,uBAAuB,YAAY;AAAA,MAC5F;AAEA,YAAM,KAAK,cAAc,eAAe,IAAI;AAE5C,YAAM,OAAO,YAAY,UAAU,EAAE,KAAK;AAAA,IAC5C,SAAS,OAAO;AACd,WAAK,kBAAkB,EAAE,OAAO,MAAM,CAAC;AAAA,IACzC;AAAA,EACF,GAxBmB;AAyBrB;",
|
|
6
6
|
"names": ["queryValue"]
|
|
7
7
|
}
|
|
@@ -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 BaseController from './base.js';\nimport { LifecyclePhase } from '../../lifecycle/types.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
|
|
4
|
+
"sourcesContent": ["import type { FastifyReply, FastifyRequest } from 'fastify';\nimport BaseController from './base.js';\nimport { LifecyclePhase } from '../../lifecycle/types.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
5
|
"mappings": ";;AACA,OAAO,oBAAoB;AAC3B,SAAS,sBAAsB;AAE/B,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
|
}
|
package/dist/webserver/util.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EntityRouteDefinition } from './webserver.interface.js';
|
|
2
|
-
declare function getEntityRouteDefinitions({ basePath, entityValidationSchema, }: {
|
|
2
|
+
declare function getEntityRouteDefinitions({ basePath, entityValidationSchema: _entityValidationSchema, }: {
|
|
3
3
|
basePath: string;
|
|
4
4
|
entityValidationSchema: any;
|
|
5
5
|
}): EntityRouteDefinition[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/webserver/util.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/webserver/util.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEtE,iBAAS,yBAAyB,CAAC,EACjC,QAAQ,EACR,sBAAsB,EAAE,uBAAuB,GAChD,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,sBAAsB,EAAE,GAAG,CAAC;CAC7B,GAAG,qBAAqB,EAAE,CA8C1B;;;;AAED,wBAGE"}
|
package/dist/webserver/util.js
CHANGED
|
@@ -2,19 +2,9 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
function getEntityRouteDefinitions({
|
|
4
4
|
basePath,
|
|
5
|
-
entityValidationSchema
|
|
5
|
+
entityValidationSchema: _entityValidationSchema
|
|
6
6
|
}) {
|
|
7
7
|
const routeDefinitions = [];
|
|
8
|
-
const idValidationSchema = {
|
|
9
|
-
type: "params",
|
|
10
|
-
schema: {
|
|
11
|
-
properties: {
|
|
12
|
-
id: { type: "integer" }
|
|
13
|
-
},
|
|
14
|
-
required: ["id"],
|
|
15
|
-
type: "object"
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
8
|
routeDefinitions.push({
|
|
19
9
|
path: `${basePath}/options`,
|
|
20
10
|
method: "GET",
|
|
@@ -28,30 +18,22 @@ function getEntityRouteDefinitions({
|
|
|
28
18
|
routeDefinitions.push({
|
|
29
19
|
path: `${basePath}/:id`,
|
|
30
20
|
method: "GET",
|
|
31
|
-
action: "getOne"
|
|
32
|
-
validationSchema: idValidationSchema
|
|
21
|
+
action: "getOne"
|
|
33
22
|
});
|
|
34
23
|
routeDefinitions.push({
|
|
35
24
|
path: `${basePath}`,
|
|
36
25
|
method: "POST",
|
|
37
|
-
action: "createOne"
|
|
38
|
-
validationSchema: entityValidationSchema
|
|
26
|
+
action: "createOne"
|
|
39
27
|
});
|
|
40
|
-
const updateOneValidationSchemas = [idValidationSchema];
|
|
41
|
-
if (entityValidationSchema) {
|
|
42
|
-
updateOneValidationSchemas.push(entityValidationSchema);
|
|
43
|
-
}
|
|
44
28
|
routeDefinitions.push({
|
|
45
29
|
path: `${basePath}/:id`,
|
|
46
30
|
method: "PUT",
|
|
47
|
-
action: "updateOne"
|
|
48
|
-
validationSchema: updateOneValidationSchemas
|
|
31
|
+
action: "updateOne"
|
|
49
32
|
});
|
|
50
33
|
routeDefinitions.push({
|
|
51
34
|
path: `${basePath}/:id`,
|
|
52
35
|
method: "DELETE",
|
|
53
|
-
action: "deleteOne"
|
|
54
|
-
validationSchema: idValidationSchema
|
|
36
|
+
action: "deleteOne"
|
|
55
37
|
});
|
|
56
38
|
return routeDefinitions;
|
|
57
39
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/webserver/util.ts"],
|
|
4
|
-
"sourcesContent": ["import type { HTTPMethods } from 'fastify';\nimport type { EntityRouteDefinition
|
|
5
|
-
"mappings": ";;AAGA,SAAS,0BAA0B;AAAA,EACjC;AAAA,EACA;
|
|
4
|
+
"sourcesContent": ["import type { HTTPMethods } from 'fastify';\nimport type { EntityRouteDefinition } from './webserver.interface.js';\n\nfunction getEntityRouteDefinitions({\n basePath,\n entityValidationSchema: _entityValidationSchema,\n}: {\n basePath: string;\n entityValidationSchema: any;\n}): EntityRouteDefinition[] {\n const routeDefinitions: EntityRouteDefinition[] = [];\n\n // Options\n routeDefinitions.push({\n path: `${basePath}/options`,\n method: 'GET' as HTTPMethods,\n action: 'options',\n });\n\n // Get many\n routeDefinitions.push({\n path: `${basePath}`,\n method: 'GET' as HTTPMethods,\n action: 'getMany',\n });\n\n // Get one\n routeDefinitions.push({\n path: `${basePath}/:id`,\n method: 'GET' as HTTPMethods,\n action: 'getOne',\n });\n\n // Create one\n routeDefinitions.push({\n path: `${basePath}`,\n method: 'POST' as HTTPMethods,\n action: 'createOne',\n });\n\n // Update one\n routeDefinitions.push({\n path: `${basePath}/:id`,\n method: 'PUT' as HTTPMethods,\n action: 'updateOne',\n });\n\n // Delete one\n routeDefinitions.push({\n path: `${basePath}/:id`,\n method: 'DELETE' as HTTPMethods,\n action: 'deleteOne',\n });\n\n return routeDefinitions;\n}\n\nexport default {\n // getEntityRoutes,\n getEntityRouteDefinitions,\n};\n"],
|
|
5
|
+
"mappings": ";;AAGA,SAAS,0BAA0B;AAAA,EACjC;AAAA,EACA,wBAAwB;AAC1B,GAG4B;AAC1B,QAAM,mBAA4C,CAAC;AAGnD,mBAAiB,KAAK;AAAA,IACpB,MAAM,GAAG,QAAQ;AAAA,IACjB,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV,CAAC;AAGD,mBAAiB,KAAK;AAAA,IACpB,MAAM,GAAG,QAAQ;AAAA,IACjB,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV,CAAC;AAGD,mBAAiB,KAAK;AAAA,IACpB,MAAM,GAAG,QAAQ;AAAA,IACjB,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV,CAAC;AAGD,mBAAiB,KAAK;AAAA,IACpB,MAAM,GAAG,QAAQ;AAAA,IACjB,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV,CAAC;AAGD,mBAAiB,KAAK;AAAA,IACpB,MAAM,GAAG,QAAQ;AAAA,IACjB,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV,CAAC;AAGD,mBAAiB,KAAK;AAAA,IACpB,MAAM,GAAG,QAAQ;AAAA,IACjB,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV,CAAC;AAED,SAAO;AACT;AApDS;AAsDT,IAAO,eAAQ;AAAA;AAAA,EAEb;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -14,6 +14,7 @@ declare class WebServer {
|
|
|
14
14
|
private applicationConfig;
|
|
15
15
|
private options;
|
|
16
16
|
private routes;
|
|
17
|
+
private readonly explicitRoutesConfigured;
|
|
17
18
|
private redisInstance;
|
|
18
19
|
private queueManager;
|
|
19
20
|
private eventManager;
|
|
@@ -50,7 +51,7 @@ declare class WebServer {
|
|
|
50
51
|
private loadRoutesFromDirectory;
|
|
51
52
|
private normalizeRouteExport;
|
|
52
53
|
private isValidRoute;
|
|
53
|
-
defineRoute({ controllerInstance, controllerName, routeMethod, routePath, routeAction, routeSchema, handlerOverride,
|
|
54
|
+
defineRoute({ controllerInstance, controllerName, routeMethod, routePath, routeAction, routeSchema, handlerOverride, }: {
|
|
54
55
|
controllerInstance: any;
|
|
55
56
|
controllerName: string;
|
|
56
57
|
routeMethod: HTTPMethods | HTTPMethods[];
|
|
@@ -58,17 +59,6 @@ declare class WebServer {
|
|
|
58
59
|
routeAction?: string;
|
|
59
60
|
routeSchema?: AnyRouteSchemaDefinition;
|
|
60
61
|
handlerOverride?: ControllerAction<any>;
|
|
61
|
-
legacyValidation?: {
|
|
62
|
-
type: 'body' | 'query' | 'params';
|
|
63
|
-
schema: {
|
|
64
|
-
[key: string]: any;
|
|
65
|
-
};
|
|
66
|
-
} | Array<{
|
|
67
|
-
type: 'body' | 'query' | 'params';
|
|
68
|
-
schema: {
|
|
69
|
-
[key: string]: any;
|
|
70
|
-
};
|
|
71
|
-
}>;
|
|
72
62
|
}): Promise<void>;
|
|
73
63
|
/**
|
|
74
64
|
* Start web server.
|
|
@@ -79,7 +69,6 @@ declare class WebServer {
|
|
|
79
69
|
*/
|
|
80
70
|
stop(): Promise<void>;
|
|
81
71
|
private buildFastifySchema;
|
|
82
|
-
private buildLegacySchema;
|
|
83
72
|
/**
|
|
84
73
|
* Check if web server is ready to accept traffic.
|
|
85
74
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webserver.d.ts","sourceRoot":"","sources":["../../src/webserver/webserver.ts"],"names":[],"mappings":"AACA,OAAgB,EACd,KAAK,eAAe,EAIpB,KAAK,WAAW,EACjB,MAAM,SAAS,CAAC;AAKjB,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,0BAA0B,EAIhC,M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O,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"}
|
|
@@ -31,7 +31,7 @@ export interface WebServerConstructorParams {
|
|
|
31
31
|
/** Web server options */
|
|
32
32
|
options: WebServerOptions;
|
|
33
33
|
/** Web server routes */
|
|
34
|
-
routes
|
|
34
|
+
routes?: WebServerRoute[];
|
|
35
35
|
/** Redis instance */
|
|
36
36
|
redisInstance: RedisInstance;
|
|
37
37
|
/** Queue manager */
|
|
@@ -58,15 +58,6 @@ export interface BaseWebServerRoute {
|
|
|
58
58
|
controller?: WebServerBaseControllerType;
|
|
59
59
|
/** Typed route handler */
|
|
60
60
|
handler?: ControllerAction<any>;
|
|
61
|
-
/** Route validation */
|
|
62
|
-
validation?: {
|
|
63
|
-
/** Validation type */
|
|
64
|
-
type: 'body' | 'query' | 'params';
|
|
65
|
-
/** Validation schema */
|
|
66
|
-
schema: {
|
|
67
|
-
[key: string]: any;
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
61
|
/** Zod-based schema definition */
|
|
71
62
|
schema?: AnyRouteSchemaDefinition;
|
|
72
63
|
}
|
|
@@ -83,21 +74,10 @@ export interface EntityWebServerRoute extends BaseWebServerRoute {
|
|
|
83
74
|
entityName: string;
|
|
84
75
|
}
|
|
85
76
|
export type WebServerRoute = DefaultWebServerRoute | EntityWebServerRoute;
|
|
86
|
-
export interface RouteValidationSchema {
|
|
87
|
-
type: 'body' | 'query' | 'params';
|
|
88
|
-
schema: {
|
|
89
|
-
type: 'object';
|
|
90
|
-
properties: {
|
|
91
|
-
[key: string]: any;
|
|
92
|
-
};
|
|
93
|
-
required: string[];
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
77
|
export interface EntityRouteDefinition {
|
|
97
78
|
path: string;
|
|
98
79
|
method: HTTPMethods | HTTPMethods[];
|
|
99
80
|
action: string;
|
|
100
|
-
validationSchema?: RouteValidationSchema | RouteValidationSchema[];
|
|
101
81
|
}
|
|
102
82
|
export interface WebServerLogConfig {
|
|
103
83
|
startUp?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webserver.interface.d.ts","sourceRoot":"","sources":["../../src/webserver/webserver.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAChG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AACpG,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8CAA8C,CAAC;AACtF,OAAO,KAAK,YAAY,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,MAAM,WAAW,qBAAqB,CACpC,OAAO,SAAS,CAAC,CAAC,UAAU,GAAG,SAAS,GAAG,SAAS,EACpD,MAAM,SAAS,CAAC,CAAC,UAAU,GAAG,SAAS,GAAG,SAAS,EACnD,KAAK,SAAS,CAAC,CAAC,UAAU,GAAG,SAAS,GAAG,SAAS,EAClD,MAAM,SAAS,MAAM,CAAC,MAAM,GAAG,GAAG,MAAM,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,GAAG,SAAS,GAAG,SAAS,EACjF,QAAQ,SAAS,CAAC,CAAC,UAAU,GAAG,SAAS,GAAG,SAAS;IAErD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AO,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,wBAAwB;IACvC,MAAM,CAAC,EAAE,8BAA8B,CAAC;IACxC,SAAS,CAAC,EAAE,iCAAiC,CAAC;CAC/C;AAED,MAAM,WAAW,gBAAgB;IAC/B,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IAEb,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IAEb,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,wDAAwD;IACxD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B,8BAA8B;IAC9B,IAAI,CAAC,EAAE,oBAAoB,CAAC;IAE5B,+BAA+B;IAC/B,MAAM,CAAC,EAAE,sBAAsB,CAAC;IAEhC,uCAAuC;IACvC,oBAAoB,EAAE,MAAM,CAAC;IAE7B,2DAA2D;IAC3D,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,GAAG,CAAC,EAAE,kBAAkB,CAAC;IAEzB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,wBAAwB,CAAC;IAEpC,+BAA+B;IAC/B,KAAK,CAAC,EAAE,qBAAqB,CAAC;CAC/B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/webserver/webserver.interface.ts"],
|
|
4
|
-
"sourcesContent": ["import type { FastifyReply, FastifyRequest, HTTPMethods, RouteGenericInterface } from 'fastify';\nimport type { DatabaseInstance } from '../database/index.js';\nimport type { QueueManager } from '../queue/index.js';\nimport type { RedisInstance } from '../redis/index.js';\nimport type { ControllerAction, WebServerBaseControllerType } from './controller/base.interface.js';\nimport type { ApplicationConfig } from '../application/base-application.interface.js';\nimport type EventManager from '../event/manager.js';\nimport type { LifecycleManager } from '../lifecycle/lifecycle-manager.js';\nimport type { z } from 'zod';\n\nexport interface RouteSchemaDefinition<\n TParams extends z.ZodTypeAny | undefined = undefined,\n TQuery extends z.ZodTypeAny | undefined = undefined,\n TBody extends z.ZodTypeAny | undefined = undefined,\n TReply extends Record<number | `${number}`, z.ZodTypeAny> | undefined = undefined,\n THeaders extends z.ZodTypeAny | undefined = undefined,\n> {\n params?: TParams;\n querystring?: TQuery;\n body?: TBody;\n response?: TReply;\n headers?: THeaders;\n}\n\ntype InferOrDefault<TZod extends z.ZodTypeAny | undefined, TFallback> = TZod extends z.ZodTypeAny\n ? z.input<TZod>\n : TFallback;\n\ntype InferResponse<TResponse> =\n TResponse extends Record<number | `${number}`, z.ZodTypeAny>\n ? z.output<TResponse[keyof TResponse]>\n : RouteGenericInterface['Reply'];\n\nexport interface RouteHandlerContext<Schema extends RouteSchemaDefinition | undefined = undefined>\n extends RouteGenericInterface {\n Params?: Schema extends RouteSchemaDefinition<infer TParams, any, any, any, any>\n ? InferOrDefault<TParams, RouteGenericInterface['Params']>\n : RouteGenericInterface['Params'];\n Querystring?: Schema extends RouteSchemaDefinition<any, infer TQuery, any, any, any>\n ? InferOrDefault<TQuery, RouteGenericInterface['Querystring']>\n : RouteGenericInterface['Querystring'];\n Body?: Schema extends RouteSchemaDefinition<any, any, infer TBody, any, any>\n ? InferOrDefault<TBody, RouteGenericInterface['Body']>\n : RouteGenericInterface['Body'];\n Headers?: Schema extends RouteSchemaDefinition<any, any, any, any, infer THeaders>\n ? InferOrDefault<THeaders, RouteGenericInterface['Headers']>\n : RouteGenericInterface['Headers'];\n Reply?: Schema extends RouteSchemaDefinition<any, any, any, infer TReply, any>\n ? InferResponse<TReply>\n : RouteGenericInterface['Reply'];\n}\n\nexport type AnyRouteSchemaDefinition = RouteSchemaDefinition<\n z.ZodTypeAny | undefined,\n z.ZodTypeAny | undefined,\n z.ZodTypeAny | undefined,\n Record<number | `${number}`, z.ZodTypeAny> | undefined,\n z.ZodTypeAny | undefined\n>;\n\nexport type RouteHandler<Schema extends RouteSchemaDefinition | undefined = undefined> = (\n request: FastifyRequest<RouteHandlerContext<Schema>>,\n reply: FastifyReply,\n) => Promise<RouteHandlerContext<Schema>['Reply'] | void> | RouteHandlerContext<Schema>['Reply'] | void;\n\nexport interface WebServerConstructorParams {\n /** Application configuration */\n applicationConfig: ApplicationConfig;\n\n /** Web server options */\n options: WebServerOptions;\n\n /** Web server routes */\n routes
|
|
4
|
+
"sourcesContent": ["import type { FastifyReply, FastifyRequest, HTTPMethods, RouteGenericInterface } from 'fastify';\nimport type { DatabaseInstance } from '../database/index.js';\nimport type { QueueManager } from '../queue/index.js';\nimport type { RedisInstance } from '../redis/index.js';\nimport type { ControllerAction, WebServerBaseControllerType } from './controller/base.interface.js';\nimport type { ApplicationConfig } from '../application/base-application.interface.js';\nimport type EventManager from '../event/manager.js';\nimport type { LifecycleManager } from '../lifecycle/lifecycle-manager.js';\nimport type { z } from 'zod';\n\nexport interface RouteSchemaDefinition<\n TParams extends z.ZodTypeAny | undefined = undefined,\n TQuery extends z.ZodTypeAny | undefined = undefined,\n TBody extends z.ZodTypeAny | undefined = undefined,\n TReply extends Record<number | `${number}`, z.ZodTypeAny> | undefined = undefined,\n THeaders extends z.ZodTypeAny | undefined = undefined,\n> {\n params?: TParams;\n querystring?: TQuery;\n body?: TBody;\n response?: TReply;\n headers?: THeaders;\n}\n\ntype InferOrDefault<TZod extends z.ZodTypeAny | undefined, TFallback> = TZod extends z.ZodTypeAny\n ? z.input<TZod>\n : TFallback;\n\ntype InferResponse<TResponse> =\n TResponse extends Record<number | `${number}`, z.ZodTypeAny>\n ? z.output<TResponse[keyof TResponse]>\n : RouteGenericInterface['Reply'];\n\nexport interface RouteHandlerContext<Schema extends RouteSchemaDefinition | undefined = undefined>\n extends RouteGenericInterface {\n Params?: Schema extends RouteSchemaDefinition<infer TParams, any, any, any, any>\n ? InferOrDefault<TParams, RouteGenericInterface['Params']>\n : RouteGenericInterface['Params'];\n Querystring?: Schema extends RouteSchemaDefinition<any, infer TQuery, any, any, any>\n ? InferOrDefault<TQuery, RouteGenericInterface['Querystring']>\n : RouteGenericInterface['Querystring'];\n Body?: Schema extends RouteSchemaDefinition<any, any, infer TBody, any, any>\n ? InferOrDefault<TBody, RouteGenericInterface['Body']>\n : RouteGenericInterface['Body'];\n Headers?: Schema extends RouteSchemaDefinition<any, any, any, any, infer THeaders>\n ? InferOrDefault<THeaders, RouteGenericInterface['Headers']>\n : RouteGenericInterface['Headers'];\n Reply?: Schema extends RouteSchemaDefinition<any, any, any, infer TReply, any>\n ? InferResponse<TReply>\n : RouteGenericInterface['Reply'];\n}\n\nexport type AnyRouteSchemaDefinition = RouteSchemaDefinition<\n z.ZodTypeAny | undefined,\n z.ZodTypeAny | undefined,\n z.ZodTypeAny | undefined,\n Record<number | `${number}`, z.ZodTypeAny> | undefined,\n z.ZodTypeAny | undefined\n>;\n\nexport type RouteHandler<Schema extends RouteSchemaDefinition | undefined = undefined> = (\n request: FastifyRequest<RouteHandlerContext<Schema>>,\n reply: FastifyReply,\n) => Promise<RouteHandlerContext<Schema>['Reply'] | void> | RouteHandlerContext<Schema>['Reply'] | void;\n\nexport interface WebServerConstructorParams {\n /** Application configuration */\n applicationConfig: ApplicationConfig;\n\n /** Web server options */\n options: WebServerOptions;\n\n /** Web server routes */\n routes?: WebServerRoute[];\n\n /** Redis instance */\n redisInstance: RedisInstance;\n\n /** Queue manager */\n queueManager: QueueManager;\n\n /** Event manager */\n eventManager: EventManager;\n\n /** Database instance */\n databaseInstance: DatabaseInstance;\n\n /** Lifecycle manager */\n lifecycleManager: LifecycleManager;\n}\n\nexport enum WebServerRouteType {\n Default = 'default',\n Entity = 'entity',\n}\n\nexport interface BaseWebServerRoute {\n /** Route type */\n type?: WebServerRouteType;\n\n /** Route path */\n path: string;\n\n /** Route controller name */\n controllerName?: string;\n\n /** Route controller */\n controller?: WebServerBaseControllerType;\n\n /** Typed route handler */\n handler?: ControllerAction<any>;\n\n /** Zod-based schema definition */\n schema?: AnyRouteSchemaDefinition;\n}\n\nexport interface DefaultWebServerRoute extends BaseWebServerRoute {\n type: WebServerRouteType.Default;\n\n /** Route method */\n method: HTTPMethods | HTTPMethods[];\n\n /** Route action */\n action?: string;\n}\n\nexport interface EntityWebServerRoute extends BaseWebServerRoute {\n type: WebServerRouteType.Entity;\n\n /** Entity name */\n entityName: string;\n}\n\nexport type WebServerRoute = DefaultWebServerRoute | EntityWebServerRoute;\n\nexport interface EntityRouteDefinition {\n path: string;\n method: HTTPMethods | HTTPMethods[];\n action: string;\n}\n\nexport interface WebServerLogConfig {\n startUp?: boolean;\n}\n\nexport interface WebServerDebugOptions {\n printRoutes?: boolean;\n simulateSlowConnection?: {\n enabled?: boolean;\n delay?: number;\n };\n}\n\nexport interface WebServerCorsBaseOptions {\n /** Whether CORS is enabled */\n enabled: boolean;\n}\n\nexport interface WebServerCorsDisabledOptionsBase {\n enabled: false;\n}\n\nexport interface WebServerCorsEnabledOptionsBase {\n enabled: true;\n}\n\nexport interface WebServerCorsEnabledOptions extends WebServerCorsEnabledOptionsBase {\n urls: string[];\n}\n\nexport type WebServerCorsOptions = WebServerCorsDisabledOptionsBase | WebServerCorsEnabledOptions;\n\nexport interface WebServerErrorsOptions {\n verbose: boolean;\n}\n\nexport interface WebServerSecurityHelmetOptions {\n enabled?: boolean;\n contentSecurityPolicy?: boolean;\n crossOriginEmbedderPolicy?: boolean;\n crossOriginOpenerPolicy?: boolean;\n crossOriginResourcePolicy?: boolean;\n dnsPrefetchControl?: boolean;\n frameguard?: boolean;\n hidePoweredBy?: boolean;\n hsts?: boolean;\n ieNoOpen?: boolean;\n noSniff?: boolean;\n originAgentCluster?: boolean;\n permittedCrossDomainPolicies?: boolean;\n referrerPolicy?: boolean;\n xssFilter?: boolean;\n}\n\nexport interface WebServerSecurityRateLimitOptions {\n enabled?: boolean;\n max?: number;\n timeWindow?: string;\n ban?: number;\n cache?: number;\n}\n\nexport interface WebServerSecurityOptions {\n helmet?: WebServerSecurityHelmetOptions;\n rateLimit?: WebServerSecurityRateLimitOptions;\n}\n\nexport interface WebServerOptions {\n /** Web server host */\n host: string;\n\n /** Web server port */\n port: number;\n\n /** Maximum request body size in bytes (default: 25MB) */\n bodyLimit?: number;\n\n /** Connection timeout in milliseconds (default: 10s) */\n connectionTimeout?: number;\n\n /** Web server CORS options */\n cors?: WebServerCorsOptions;\n\n /** Web server error options */\n errors?: WebServerErrorsOptions;\n\n /** Web server controllers directory */\n controllersDirectory: string;\n\n /** Optional directory containing route definition files */\n routesDirectory?: string;\n\n log?: WebServerLogConfig;\n\n /** Web server security options (helmet, rate limiting) */\n security?: WebServerSecurityOptions;\n\n /** Web server debug options */\n debug?: WebServerDebugOptions;\n}\n\n// export interface WebServerLogParams {\n// /** Method */\n// Method: string;\n\n// /** Path */\n// Path: string;\n\n// /** Status code */\n// Status: number;\n\n// /** IP address */\n// IP?: string;\n\n// /** Execution time */\n// Time?: string;\n\n// [key: string]: unknown;\n// }\n"],
|
|
5
5
|
"mappings": "AA2FO,IAAK,qBAAL,kBAAKA,wBAAL;AACL,EAAAA,oBAAA,aAAU;AACV,EAAAA,oBAAA,YAAS;AAFC,SAAAA;AAAA,GAAA;",
|
|
6
6
|
"names": ["WebServerRouteType"]
|
|
7
7
|
}
|