@forinda/kickjs 0.1.6 → 1.4.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js DELETED
@@ -1,882 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- var __esm = (fn, res) => function __init() {
10
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
11
- };
12
- var __export = (target, all) => {
13
- for (var name in all)
14
- __defProp(target, name, { get: all[name], enumerable: true });
15
- };
16
- var __copyProps = (to, from, except, desc) => {
17
- if (from && typeof from === "object" || typeof from === "function") {
18
- for (let key of __getOwnPropNames(from))
19
- if (!__hasOwnProp.call(to, key) && key !== except)
20
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
- }
22
- return to;
23
- };
24
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
- // If the importer is in node compatibility mode or this is not an ESM
26
- // file that has been converted to a CommonJS file using a Babel-
27
- // compatible transform (i.e. "__esModule" has not been set), then set
28
- // "default" to the CommonJS "module.exports" for node compatibility.
29
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30
- mod
31
- ));
32
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
-
34
- // src/cli/utils/config-loader.ts
35
- async function loadKickConfig(cwd) {
36
- const workingDir = cwd || process.cwd();
37
- for (const configFileName of CONFIG_FILE_NAMES) {
38
- const configPath = import_node_path.default.resolve(workingDir, configFileName);
39
- if ((0, import_node_fs.existsSync)(configPath)) {
40
- try {
41
- const configModule = await import(configPath);
42
- const config = configModule.default || configModule;
43
- return {
44
- ...config,
45
- configPath
46
- };
47
- } catch (error) {
48
- console.warn(`\u26A0\uFE0F Failed to load config from ${configPath}:`, error);
49
- }
50
- }
51
- }
52
- return getDefaultConfig();
53
- }
54
- function getDefaultConfig() {
55
- return {
56
- app: {
57
- name: "KickJS App",
58
- port: 3e3,
59
- host: "localhost",
60
- prefix: "",
61
- env: "development"
62
- },
63
- dev: {
64
- port: 3e3,
65
- host: "localhost",
66
- entry: "src/index.ts",
67
- watch: true,
68
- env: {
69
- NODE_ENV: "development"
70
- }
71
- },
72
- start: {
73
- port: 3e3,
74
- host: "0.0.0.0",
75
- entry: "dist/index.js",
76
- env: {
77
- NODE_ENV: "production"
78
- }
79
- },
80
- structure: {
81
- domainRoot: "src/domains",
82
- domainFolders: [
83
- "controllers",
84
- "services",
85
- "domain"
86
- ],
87
- defaultDomain: "app"
88
- },
89
- generators: {
90
- controllerRoot: "src/domains/app/controllers"
91
- }
92
- };
93
- }
94
- function getAppConfig(config, overrides = {}) {
95
- return {
96
- ...getDefaultConfig().app,
97
- ...config.app,
98
- ...overrides
99
- };
100
- }
101
- var import_node_fs, import_node_path, CONFIG_FILE_NAMES;
102
- var init_config_loader = __esm({
103
- "src/cli/utils/config-loader.ts"() {
104
- "use strict";
105
- import_node_fs = require("fs");
106
- import_node_path = __toESM(require("path"));
107
- CONFIG_FILE_NAMES = [
108
- "kick.config.ts",
109
- "kick.config.js",
110
- "kick.config.mjs",
111
- "kickjs.config.ts",
112
- "kickjs.config.js",
113
- "kickjs.config.mjs"
114
- ];
115
- __name(loadKickConfig, "loadKickConfig");
116
- __name(getDefaultConfig, "getDefaultConfig");
117
- __name(getAppConfig, "getAppConfig");
118
- }
119
- });
120
-
121
- // src/core/utils/app-config.ts
122
- var app_config_exports = {};
123
- __export(app_config_exports, {
124
- getConfigFromEnv: () => getConfigFromEnv,
125
- loadAppConfig: () => loadAppConfig
126
- });
127
- async function loadAppConfig(overrides = {}) {
128
- const kickConfig = await loadKickConfig();
129
- return getAppConfig(kickConfig, overrides);
130
- }
131
- function getConfigFromEnv() {
132
- return {
133
- port: process.env.PORT ? parseInt(process.env.PORT) : void 0,
134
- host: process.env.HOST || void 0,
135
- env: process.env.NODE_ENV || void 0
136
- };
137
- }
138
- var init_app_config = __esm({
139
- "src/core/utils/app-config.ts"() {
140
- "use strict";
141
- init_config_loader();
142
- __name(loadAppConfig, "loadAppConfig");
143
- __name(getConfigFromEnv, "getConfigFromEnv");
144
- }
145
- });
146
-
147
- // src/index.ts
148
- var index_exports = {};
149
- __export(index_exports, {
150
- AutoBind: () => AutoBind,
151
- BaseKickMiddleware: () => BaseKickMiddleware,
152
- BaseKickPlugin: () => BaseKickPlugin,
153
- KICK_CONTROLLER_METADATA_KEYS: () => KICK_CONTROLLER_METADATA_KEYS,
154
- KICK_MODULE_KEYS: () => KICK_MODULE_KEYS,
155
- KickApp: () => KickApp,
156
- KickController: () => KickController,
157
- KickDelete: () => KickDelete,
158
- KickGet: () => KickGet,
159
- KickInject: () => KickInject,
160
- KickInjectable: () => KickInjectable,
161
- KickMiddleware: () => KickMiddleware,
162
- KickPatch: () => KickPatch,
163
- KickPost: () => KickPost,
164
- KickPut: () => KickPut,
165
- RouteMapper: () => RouteMapper,
166
- bindClassMethods: () => bindClassMethods,
167
- combineRoutePaths: () => combineRoutePaths,
168
- createKickApp: () => createKickApp,
169
- createKickAppWithConfig: () => createKickAppWithConfig,
170
- createKickConfig: () => createKickConfig,
171
- createModule: () => createModule,
172
- defineAppConfig: () => defineAppConfig,
173
- defineDevConfig: () => defineDevConfig,
174
- defineStartConfig: () => defineStartConfig,
175
- getConfigFromEnv: () => getConfigFromEnv,
176
- getMiddlewareMetadata: () => getMiddlewareMetadata,
177
- isKickMiddleware: () => isKickMiddleware,
178
- loadAppConfig: () => loadAppConfig,
179
- mapController: () => mapController,
180
- normalizeRoutePath: () => normalizeRoutePath
181
- });
182
- module.exports = __toCommonJS(index_exports);
183
-
184
- // src/core/index.ts
185
- var import_reflect_metadata = require("reflect-metadata");
186
-
187
- // src/core/constants/di-keys.ts
188
- var KICK_MODULE_KEYS = {
189
- KickControllerType: Symbol.for("Kick:ControllerType"),
190
- KickMiddlewareType: Symbol.for("Kick:MiddlewareType")
191
- };
192
- var KICK_CONTROLLER_METADATA_KEYS = {
193
- path: Symbol.for("Kick:controller:path"),
194
- options: Symbol.for("Kick:controller:options"),
195
- routes: Symbol.for("Kick:controller:routes"),
196
- middlewares: Symbol.for("Kick:controller:middlewares"),
197
- middlewareOptions: Symbol.for("Kick:middleware:options"),
198
- isMiddleware: Symbol.for("Kick:middleware:isMiddleware")
199
- };
200
-
201
- // src/core/decorators/route.ts
202
- function createKickRoute(createOptions) {
203
- return function(path2, options = {}) {
204
- return function(target, propertyKey, descriptor) {
205
- if (typeof descriptor.value !== "function") {
206
- throw new Error("[KickRoute] Decorator can only be applied to methods.");
207
- }
208
- const routeMetadata = {
209
- path: path2,
210
- method: createOptions.method,
211
- handlerName: propertyKey,
212
- handler: descriptor.value,
213
- middlewares: options.middlewares ?? []
214
- };
215
- const existingRoutes = Reflect.getMetadata(KICK_CONTROLLER_METADATA_KEYS.routes, target.constructor) || [];
216
- existingRoutes.push(routeMetadata);
217
- Reflect.defineMetadata(KICK_CONTROLLER_METADATA_KEYS.routes, existingRoutes, target.constructor);
218
- };
219
- };
220
- }
221
- __name(createKickRoute, "createKickRoute");
222
- function KickGet(path2, options) {
223
- return createKickRoute({
224
- method: "GET"
225
- })(path2, options);
226
- }
227
- __name(KickGet, "KickGet");
228
- function KickPost(path2, options) {
229
- return createKickRoute({
230
- method: "POST"
231
- })(path2, options);
232
- }
233
- __name(KickPost, "KickPost");
234
- function KickPut(path2, options) {
235
- return createKickRoute({
236
- method: "PUT"
237
- })(path2, options);
238
- }
239
- __name(KickPut, "KickPut");
240
- function KickPatch(path2, options) {
241
- return createKickRoute({
242
- method: "PATCH"
243
- })(path2, options);
244
- }
245
- __name(KickPatch, "KickPatch");
246
- function KickDelete(path2, options) {
247
- return createKickRoute({
248
- method: "DELETE"
249
- })(path2, options);
250
- }
251
- __name(KickDelete, "KickDelete");
252
-
253
- // src/core/decorators/controller.ts
254
- var import_inversify = require("inversify");
255
-
256
- // src/core/utils/bind-class-methods.ts
257
- function bindClassMethods(instance) {
258
- const proto = Object.getPrototypeOf(instance);
259
- const methods = Object.getOwnPropertyNames(proto).filter((prop) => typeof instance[prop] === "function" && prop !== "constructor");
260
- methods.forEach((method) => {
261
- instance[method] = instance[method].bind(instance);
262
- });
263
- }
264
- __name(bindClassMethods, "bindClassMethods");
265
-
266
- // src/core/decorators/controller.ts
267
- function KickController(path2, options) {
268
- return function(target) {
269
- (0, import_inversify.decorate)((0, import_inversify.injectable)("Request"), target);
270
- bindClassMethods(target.prototype);
271
- Reflect.defineMetadata(KICK_CONTROLLER_METADATA_KEYS.path, path2, target);
272
- Reflect.defineMetadata(KICK_CONTROLLER_METADATA_KEYS.options, options || {}, target);
273
- };
274
- }
275
- __name(KickController, "KickController");
276
-
277
- // src/core/decorators/auto-bind.ts
278
- function AutoBind(target) {
279
- bindClassMethods(target.prototype);
280
- }
281
- __name(AutoBind, "AutoBind");
282
-
283
- // src/core/decorators/middleware.ts
284
- var import_inversify2 = require("inversify");
285
- function KickMiddleware(options = {}) {
286
- return function(target) {
287
- AutoBind(target);
288
- (0, import_inversify2.decorate)((0, import_inversify2.injectable)(), target);
289
- const middlewareMetadata = {
290
- name: options.name || target.name,
291
- priority: options.priority || 0,
292
- global: options.global || false,
293
- tags: options.tags || [],
294
- className: target.name
295
- };
296
- Reflect.defineMetadata(KICK_CONTROLLER_METADATA_KEYS.middlewareOptions, middlewareMetadata, target);
297
- Reflect.defineMetadata(KICK_CONTROLLER_METADATA_KEYS.isMiddleware, true, target);
298
- };
299
- }
300
- __name(KickMiddleware, "KickMiddleware");
301
- function isKickMiddleware(target) {
302
- return Reflect.getMetadata(KICK_CONTROLLER_METADATA_KEYS.isMiddleware, target) === true;
303
- }
304
- __name(isKickMiddleware, "isKickMiddleware");
305
- function getMiddlewareMetadata(target) {
306
- return Reflect.getMetadata(KICK_CONTROLLER_METADATA_KEYS.middlewareOptions, target);
307
- }
308
- __name(getMiddlewareMetadata, "getMiddlewareMetadata");
309
-
310
- // src/core/utils/normalize-route-path.ts
311
- function normalizeRoutePath(path2) {
312
- if (typeof path2 !== "string") {
313
- throw new Error("Invalid path type");
314
- }
315
- if (!path2.startsWith("/")) {
316
- path2 = `/${path2}`;
317
- }
318
- if (path2.endsWith("/")) {
319
- path2 = path2.slice(0, -1);
320
- }
321
- return path2;
322
- }
323
- __name(normalizeRoutePath, "normalizeRoutePath");
324
- function combineRoutePaths(basePath, routePath) {
325
- const base = basePath === "" ? "" : basePath.replace(/\/$/, "");
326
- const route = routePath === "" ? "" : routePath;
327
- const full = `${base}${route}`;
328
- return normalizeRoutePath(full === "" ? "/" : full);
329
- }
330
- __name(combineRoutePaths, "combineRoutePaths");
331
-
332
- // src/core/utils/controller-mapper.ts
333
- function mapController(controller) {
334
- const basePath = Reflect.getMetadata(KICK_CONTROLLER_METADATA_KEYS.path, controller.constructor) || "";
335
- const routes = Reflect.getMetadata(KICK_CONTROLLER_METADATA_KEYS.routes, controller.constructor) || [];
336
- const baseOptions = Reflect.getMetadata(KICK_CONTROLLER_METADATA_KEYS.options, controller.constructor) || {};
337
- return routes.map((route) => ({
338
- ...route,
339
- path: combineRoutePaths(basePath, route.path),
340
- middlewares: [
341
- ...baseOptions.middlewares || [],
342
- ...route.middlewares || []
343
- ]
344
- }));
345
- }
346
- __name(mapController, "mapController");
347
-
348
- // src/core/utils/di.ts
349
- var import_inversify3 = require("inversify");
350
- var KickInject = import_inversify3.inject;
351
- var KickInjectable = import_inversify3.injectable;
352
-
353
- // src/core/utils/route-mapper.ts
354
- var RouteMapper = class _RouteMapper {
355
- static {
356
- __name(this, "RouteMapper");
357
- }
358
- /**
359
- * Creates a contextual handler that injects request context into controller methods
360
- * @param controller - The controller instance
361
- * @param route - The route metadata
362
- * @param prefix - Optional prefix to prepend to route paths
363
- * @returns Express-compatible handler function
364
- */
365
- static createContextualHandler(controller, route, prefix = "") {
366
- return (req, res, next) => {
367
- const requestId = `req_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
368
- const requestContext = {
369
- req,
370
- res,
371
- next,
372
- meta: {
373
- routePath: _RouteMapper.buildRoutePath(prefix, route.path),
374
- method: route.method,
375
- controllerName: controller.constructor.name,
376
- handlerName: route.handlerName,
377
- startTime: Date.now(),
378
- requestId
379
- }
380
- };
381
- try {
382
- const result = route.handler.call(controller, requestContext);
383
- if (result instanceof Promise) {
384
- result.catch((error) => {
385
- console.error(`[${controller.constructor.name}:${route.handlerName}] Error:`, error);
386
- if (!res.headersSent) {
387
- res.status(500).json({
388
- error: "Internal Server Error",
389
- requestId: requestContext.meta.requestId
390
- });
391
- }
392
- });
393
- }
394
- return result;
395
- } catch (error) {
396
- console.error(`[${controller.constructor.name}:${route.handlerName}] Error:`, error);
397
- if (!res.headersSent) {
398
- res.status(500).json({
399
- error: "Internal Server Error",
400
- requestId: requestContext.meta.requestId
401
- });
402
- }
403
- }
404
- };
405
- }
406
- /**
407
- * Builds the full route path by combining prefix and route path
408
- * @param prefix - The prefix to prepend
409
- * @param routePath - The route path
410
- * @returns Combined route path
411
- */
412
- static buildRoutePath(prefix, routePath) {
413
- const normalizedPrefix = prefix.replace(/\/+$/, "");
414
- const normalizedRoutePath = routePath.startsWith("/") ? routePath : `/${routePath}`;
415
- if (!normalizedPrefix) {
416
- return normalizedRoutePath;
417
- }
418
- return combineRoutePaths(normalizedPrefix, normalizedRoutePath);
419
- }
420
- /**
421
- * Maps a controller to its routes with optional prefix
422
- * @param controller - The controller instance
423
- * @param routes - The route metadata array
424
- * @param prefix - Optional prefix to prepend to all routes
425
- * @returns Array of mapped route information
426
- */
427
- static mapControllerRoutes(controller, routes, prefix = "") {
428
- return routes.map((route) => ({
429
- ...route,
430
- fullPath: _RouteMapper.buildRoutePath(prefix, route.path),
431
- handler: _RouteMapper.createContextualHandler(controller, route, prefix),
432
- controllerName: controller.constructor.name
433
- }));
434
- }
435
- /**
436
- * Logs route registration information
437
- * @param method - HTTP method
438
- * @param path - Route path
439
- * @param handlerName - Handler method name
440
- * @param controllerName - Controller class name
441
- * @param prefix - Optional prefix used
442
- */
443
- static logRouteRegistration(method, path2, handlerName, controllerName, prefix) {
444
- const _prefixInfo = prefix ? ` [prefix: ${prefix}]` : "";
445
- }
446
- };
447
-
448
- // src/core/utils/index.ts
449
- init_app_config();
450
-
451
- // src/core/app/index.ts
452
- var import_http = require("http");
453
- var import_events = require("events");
454
- var import_inversify4 = require("inversify");
455
- function _ts_decorate(decorators, target, key, desc) {
456
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
457
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
458
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
459
- return c > 3 && r && Object.defineProperty(target, key, r), r;
460
- }
461
- __name(_ts_decorate, "_ts_decorate");
462
- function _ts_metadata(k, v) {
463
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
464
- }
465
- __name(_ts_metadata, "_ts_metadata");
466
- var KickApp = class extends import_events.EventEmitter {
467
- static {
468
- __name(this, "KickApp");
469
- }
470
- context;
471
- name;
472
- prefix;
473
- config;
474
- container;
475
- _isInitialized = false;
476
- _state = {};
477
- constructor(context, name = "KickApp", prefix = "", config) {
478
- super();
479
- this.context = context;
480
- this.name = name;
481
- this.prefix = prefix;
482
- this.config = config;
483
- this.container = new import_inversify4.Container({
484
- autobind: true
485
- });
486
- this.emit("created", {
487
- name: this.name,
488
- prefix: this.prefix,
489
- config: this.config
490
- });
491
- }
492
- get isInitialized() {
493
- return this._isInitialized;
494
- }
495
- get controllers() {
496
- try {
497
- return this.container.getAll(KICK_MODULE_KEYS.KickControllerType);
498
- } catch {
499
- return [];
500
- }
501
- }
502
- get state() {
503
- return {
504
- ...this._state
505
- };
506
- }
507
- setState(key, value) {
508
- const oldValue = this._state[key];
509
- this._state[key] = value;
510
- this.emit("state:changed", {
511
- key,
512
- value,
513
- oldValue
514
- });
515
- this.emit(`state:${key}`, {
516
- value,
517
- oldValue
518
- });
519
- }
520
- getState(key) {
521
- return this._state[key];
522
- }
523
- onStateChange(key, listener) {
524
- this.on(`state:${key}`, listener);
525
- }
526
- offStateChange(key, listener) {
527
- this.off(`state:${key}`, listener);
528
- }
529
- /**
530
- * Get a configuration value by key path (supports nested access like 'database.host')
531
- */
532
- getConfig(key) {
533
- if (!this.config) return void 0;
534
- if (!key) return this.config;
535
- return key.split(".").reduce((obj, k) => obj?.[k], this.config);
536
- }
537
- /**
538
- * Check if a configuration key exists
539
- */
540
- hasConfig(key) {
541
- return this.getConfig(key) !== void 0;
542
- }
543
- /**
544
- * Get config value with fallback
545
- */
546
- getConfigOrDefault(key, defaultValue) {
547
- const value = this.getConfig(key);
548
- return value !== void 0 ? value : defaultValue;
549
- }
550
- loadPlugin(plugins) {
551
- if (!Array.isArray(plugins)) {
552
- plugins = [
553
- plugins
554
- ];
555
- }
556
- plugins.forEach((plugin) => {
557
- plugin.install(this.context);
558
- this.emit("plugin:loaded", {
559
- plugin
560
- });
561
- });
562
- return this;
563
- }
564
- registerMiddleware(middleware) {
565
- if (!Array.isArray(middleware)) {
566
- middleware = [
567
- middleware
568
- ];
569
- }
570
- const sortedMiddleware = middleware.sort((a, b) => {
571
- const metadataA = Reflect.getMetadata(KICK_CONTROLLER_METADATA_KEYS.middlewareOptions, a.constructor) || {
572
- priority: 0
573
- };
574
- const metadataB = Reflect.getMetadata(KICK_CONTROLLER_METADATA_KEYS.middlewareOptions, b.constructor) || {
575
- priority: 0
576
- };
577
- return metadataA.priority - metadataB.priority;
578
- });
579
- this.context.middlewares.push(...sortedMiddleware);
580
- sortedMiddleware.forEach((mw) => {
581
- const metadata = Reflect.getMetadata(KICK_CONTROLLER_METADATA_KEYS.middlewareOptions, mw.constructor);
582
- if (metadata) {
583
- this.emit("middleware:registered:detailed", {
584
- middleware: mw,
585
- metadata,
586
- className: mw.constructor.name
587
- });
588
- } else {
589
- console.log(`[KickApp]: Registered global middleware: ${mw.constructor.name}`);
590
- }
591
- });
592
- this.emit("middleware:registered", {
593
- count: sortedMiddleware.length
594
- });
595
- return this;
596
- }
597
- mountMiddlewares() {
598
- this.context.middlewares.forEach((middleware) => {
599
- this.context.app.use(middleware.use);
600
- });
601
- this.emit("middlewares:mounted", {
602
- count: this.context.middlewares.length
603
- });
604
- return this;
605
- }
606
- loadModules(modules) {
607
- modules.forEach((module2) => {
608
- module2.install(this.container);
609
- this.emit("module:loaded", {
610
- module: module2.name
611
- });
612
- });
613
- this.extractMiddlewaresFromContainer();
614
- this.mapControllers();
615
- this._isInitialized = true;
616
- this.setState("isInitialized", true);
617
- this.setState("modulesCount", modules.length);
618
- this.emit("initialized", this.getStats());
619
- return this;
620
- }
621
- extractMiddlewaresFromContainer() {
622
- try {
623
- const middlewares = this.container.getAll(KICK_MODULE_KEYS.KickMiddlewareType);
624
- if (middlewares.length > 0) {
625
- this.registerMiddleware(middlewares);
626
- }
627
- } catch {
628
- console.warn("[KickApp]: No middlewares found in DI container");
629
- }
630
- }
631
- mapControllers() {
632
- try {
633
- const controllers = this.container.getAll(KICK_MODULE_KEYS.KickControllerType);
634
- let routeCount = 0;
635
- controllers.forEach((controller) => {
636
- const routes = mapController(controller);
637
- const mappedRoutes = RouteMapper.mapControllerRoutes(controller, routes, this.prefix);
638
- mappedRoutes.forEach((mappedRoute) => {
639
- const expressMethod = mappedRoute.method.toLowerCase();
640
- if (typeof this.context.app[expressMethod] === "function") {
641
- RouteMapper.logRouteRegistration(mappedRoute.method, mappedRoute.fullPath, mappedRoute.handlerName, mappedRoute.controllerName, this.prefix || void 0);
642
- this.context.app[expressMethod](mappedRoute.fullPath, mappedRoute.handler);
643
- this.context.requestHandlers[`${mappedRoute.method}:${mappedRoute.fullPath}`] = {
644
- ...mappedRoute,
645
- path: mappedRoute.fullPath
646
- };
647
- this.emit("route:registered", {
648
- method: mappedRoute.method,
649
- path: mappedRoute.fullPath,
650
- handler: mappedRoute.handlerName,
651
- controller: mappedRoute.controllerName,
652
- prefix: this.prefix
653
- });
654
- routeCount++;
655
- }
656
- });
657
- this.emit("controller:mapped", {
658
- controller: controller.constructor.name,
659
- routeCount: mappedRoutes.length,
660
- prefix: this.prefix
661
- });
662
- });
663
- this.setState("controllersCount", controllers.length);
664
- this.setState("routesCount", routeCount);
665
- this.setState("routePrefix", this.prefix);
666
- } catch (error) {
667
- this.emit("error", {
668
- type: "controller-mapping",
669
- error
670
- });
671
- }
672
- }
673
- getContainer() {
674
- return this.container;
675
- }
676
- getStats() {
677
- return {
678
- name: this.name,
679
- isInitialized: this._isInitialized,
680
- controllersCount: this.controllers.length,
681
- middlewaresCount: this.context.middlewares.length,
682
- routes: Object.keys(this.context.requestHandlers),
683
- routesCount: Object.keys(this.context.requestHandlers).length,
684
- state: this.state
685
- };
686
- }
687
- addErrorHandler(handler) {
688
- this.on("error", handler);
689
- }
690
- handleError(error, context) {
691
- this.emit("error", {
692
- error,
693
- context,
694
- timestamp: Date.now()
695
- });
696
- }
697
- addRequestInterceptor(interceptor) {
698
- this.context.app.use((req, res, next) => {
699
- try {
700
- interceptor(req, res, next);
701
- } catch (error) {
702
- this.handleError(error, {
703
- req: req.url,
704
- method: req.method
705
- });
706
- next(error);
707
- }
708
- });
709
- }
710
- };
711
- KickApp = _ts_decorate([
712
- AutoBind,
713
- _ts_metadata("design:type", Function),
714
- _ts_metadata("design:paramtypes", [
715
- typeof KickApplicationContext === "undefined" ? Object : KickApplicationContext,
716
- String,
717
- String,
718
- typeof KickAppConfig === "undefined" ? Object : KickAppConfig
719
- ])
720
- ], KickApp);
721
- function createKickApp(options) {
722
- const appContext = {
723
- requestHandlers: {},
724
- middlewares: [],
725
- app: options.app
726
- };
727
- const kickApp = new KickApp(appContext, options.name || "KickApp", options.prefix || "", options.config);
728
- if (kickApp.config) {
729
- }
730
- if (options.plugins) {
731
- kickApp.loadPlugin(options.plugins);
732
- }
733
- if (options.globalMiddlewares) {
734
- kickApp.registerMiddleware(options.globalMiddlewares);
735
- }
736
- kickApp.loadModules(options.modules);
737
- kickApp.mountMiddlewares();
738
- const server = (0, import_http.createServer)(kickApp.context.app);
739
- const kickServer = {
740
- // Server methods
741
- listen: server.listen.bind(server),
742
- close: server.close.bind(server),
743
- address: server.address.bind(server),
744
- getConnections: server.getConnections.bind(server),
745
- on: server.on.bind(server),
746
- off: server.off.bind(server),
747
- emit: server.emit.bind(server),
748
- // KickApp instance and methods
749
- kickApp,
750
- app: kickApp.context.app,
751
- // Convenience methods
752
- getStats: /* @__PURE__ */ __name(() => kickApp.getStats(), "getStats"),
753
- getState: /* @__PURE__ */ __name(() => kickApp.state, "getState"),
754
- setState: /* @__PURE__ */ __name((key, value) => kickApp.setState(key, value), "setState"),
755
- onStateChange: /* @__PURE__ */ __name((key, listener) => kickApp.onStateChange(key, listener), "onStateChange"),
756
- onKickEvent: /* @__PURE__ */ __name((event, listener) => kickApp.on(event, listener), "onKickEvent"),
757
- offKickEvent: /* @__PURE__ */ __name((event, listener) => kickApp.off(event, listener), "offKickEvent"),
758
- emitKickEvent: /* @__PURE__ */ __name((event, data) => kickApp.emit(event, data), "emitKickEvent"),
759
- addErrorHandler: /* @__PURE__ */ __name((handler) => kickApp.addErrorHandler(handler), "addErrorHandler"),
760
- handleError: /* @__PURE__ */ __name((error, context) => kickApp.handleError(error, context), "handleError")
761
- };
762
- kickServer.addErrorHandler((errorData) => {
763
- console.error(`[Server:${kickApp.name}] Unhandled error:`, errorData);
764
- });
765
- return kickServer;
766
- }
767
- __name(createKickApp, "createKickApp");
768
- async function createKickAppWithConfig(options) {
769
- const { loadAppConfig: loadAppConfig2, getConfigFromEnv: getConfigFromEnv2 } = await Promise.resolve().then(() => (init_app_config(), app_config_exports));
770
- const envConfig = getConfigFromEnv2();
771
- const appConfig = await loadAppConfig2({
772
- ...envConfig,
773
- ...options.configOverrides
774
- });
775
- const appOptions = {
776
- ...options,
777
- name: options.name || appConfig.name,
778
- prefix: options.prefix || appConfig.prefix,
779
- config: appConfig
780
- };
781
- return createKickApp(appOptions);
782
- }
783
- __name(createKickAppWithConfig, "createKickAppWithConfig");
784
-
785
- // src/core/base/base-plugin.ts
786
- var BaseKickPlugin = class {
787
- static {
788
- __name(this, "BaseKickPlugin");
789
- }
790
- };
791
-
792
- // src/core/base/base-middleware.ts
793
- var BaseKickMiddleware = class {
794
- static {
795
- __name(this, "BaseKickMiddleware");
796
- }
797
- };
798
-
799
- // src/core/module.ts
800
- var import_inversify5 = require("inversify");
801
- var createModule = /* @__PURE__ */ __name((name, options) => {
802
- const { controllers = [], middlewares = [] } = options;
803
- const uniqueControllers = new Set(controllers);
804
- const uniqueMiddlewares = new Set(middlewares);
805
- const module2 = new import_inversify5.ContainerModule(({ bind }) => {
806
- uniqueControllers.forEach((controller) => {
807
- const bindingKey = KICK_MODULE_KEYS.KickControllerType;
808
- bind(bindingKey).to(controller);
809
- bind(controller).toSelf();
810
- });
811
- uniqueMiddlewares.forEach((middleware) => {
812
- const bindingKey = KICK_MODULE_KEYS.KickMiddlewareType;
813
- bind(bindingKey).to(middleware);
814
- bind(middleware).toSelf();
815
- });
816
- });
817
- return {
818
- /**
819
- * Installs the module into the provided Inversify container.
820
- */
821
- install: /* @__PURE__ */ __name((container) => {
822
- container.load(module2);
823
- }, "install"),
824
- name
825
- };
826
- }, "createModule");
827
-
828
- // src/cli/utils/config-helpers.ts
829
- function createKickConfig(config) {
830
- return config;
831
- }
832
- __name(createKickConfig, "createKickConfig");
833
- function defineAppConfig(config) {
834
- return config;
835
- }
836
- __name(defineAppConfig, "defineAppConfig");
837
- function defineDevConfig(config) {
838
- return config;
839
- }
840
- __name(defineDevConfig, "defineDevConfig");
841
- function defineStartConfig(config) {
842
- return config;
843
- }
844
- __name(defineStartConfig, "defineStartConfig");
845
-
846
- // src/index.ts
847
- init_app_config();
848
- // Annotate the CommonJS export names for ESM import in node:
849
- 0 && (module.exports = {
850
- AutoBind,
851
- BaseKickMiddleware,
852
- BaseKickPlugin,
853
- KICK_CONTROLLER_METADATA_KEYS,
854
- KICK_MODULE_KEYS,
855
- KickApp,
856
- KickController,
857
- KickDelete,
858
- KickGet,
859
- KickInject,
860
- KickInjectable,
861
- KickMiddleware,
862
- KickPatch,
863
- KickPost,
864
- KickPut,
865
- RouteMapper,
866
- bindClassMethods,
867
- combineRoutePaths,
868
- createKickApp,
869
- createKickAppWithConfig,
870
- createKickConfig,
871
- createModule,
872
- defineAppConfig,
873
- defineDevConfig,
874
- defineStartConfig,
875
- getConfigFromEnv,
876
- getMiddlewareMetadata,
877
- isKickMiddleware,
878
- loadAppConfig,
879
- mapController,
880
- normalizeRoutePath
881
- });
882
- //# sourceMappingURL=index.js.map