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