@forinda/kickjs 1.6.0 → 1.7.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.
Files changed (104) hide show
  1. package/dist/chunk-DVVP7zzD.js +7 -0
  2. package/dist/core/adapter.d.ts +109 -0
  3. package/dist/core/adapter.d.ts.map +1 -0
  4. package/dist/core/adapter.js +0 -0
  5. package/dist/core/app-module.d.ts +28 -0
  6. package/dist/core/app-module.d.ts.map +1 -0
  7. package/dist/core/app-module.js +0 -0
  8. package/dist/core/cache.d.ts +93 -0
  9. package/dist/core/cache.d.ts.map +1 -0
  10. package/dist/core/cache.js +57 -0
  11. package/dist/core/container.d.ts +63 -0
  12. package/dist/core/container.d.ts.map +1 -0
  13. package/dist/core/container.js +117 -0
  14. package/dist/core/cron.d.ts +28 -0
  15. package/dist/core/cron.d.ts.map +1 -0
  16. package/dist/core/cron.js +22 -0
  17. package/dist/core/decorators.d.ts +152 -0
  18. package/dist/core/decorators.d.ts.map +1 -0
  19. package/dist/core/decorators.js +141 -0
  20. package/dist/core/errors.d.ts +64 -0
  21. package/dist/core/errors.d.ts.map +1 -0
  22. package/dist/core/errors.js +67 -0
  23. package/dist/core/index.d.ts +14 -0
  24. package/dist/core/index.d.ts.map +1 -0
  25. package/dist/core/interfaces.d.ts +44 -0
  26. package/dist/core/interfaces.d.ts.map +1 -0
  27. package/dist/core/interfaces.js +25 -0
  28. package/dist/core/logger.d.ts +43 -0
  29. package/dist/core/logger.d.ts.map +1 -0
  30. package/dist/core/logger.js +54 -0
  31. package/dist/core/path.d.ts +21 -0
  32. package/dist/core/path.d.ts.map +1 -0
  33. package/dist/core/path.js +12 -0
  34. package/dist/core/plugin.d.ts +90 -0
  35. package/dist/core/plugin.d.ts.map +1 -0
  36. package/dist/core/plugin.js +0 -0
  37. package/dist/core/reactivity.d.ts +83 -0
  38. package/dist/core/reactivity.d.ts.map +1 -0
  39. package/dist/core/reactivity.js +101 -0
  40. package/dist/core-B6Okew3W.js +7 -0
  41. package/dist/http/application.d.ts +103 -0
  42. package/dist/http/application.d.ts.map +1 -0
  43. package/dist/http/application.js +167 -0
  44. package/dist/http/bootstrap.d.ts +22 -0
  45. package/dist/http/bootstrap.d.ts.map +1 -0
  46. package/dist/http/bootstrap.js +40 -0
  47. package/dist/http/context.d.ts +129 -0
  48. package/dist/http/context.d.ts.map +1 -0
  49. package/dist/http/context.js +115 -0
  50. package/dist/http/index.d.ts +16 -0
  51. package/dist/http/index.d.ts.map +1 -0
  52. package/dist/http/middleware/cors.d.ts +43 -0
  53. package/dist/http/middleware/cors.d.ts.map +1 -0
  54. package/dist/http/middleware/cors.js +31 -0
  55. package/dist/http/middleware/csrf.d.ts +47 -0
  56. package/dist/http/middleware/csrf.d.ts.map +1 -0
  57. package/dist/http/middleware/csrf.js +25 -0
  58. package/dist/http/middleware/error-handler.d.ts +6 -0
  59. package/dist/http/middleware/error-handler.d.ts.map +1 -0
  60. package/dist/http/middleware/error-handler.js +37 -0
  61. package/dist/http/middleware/helmet.d.ts +36 -0
  62. package/dist/http/middleware/helmet.d.ts.map +1 -0
  63. package/dist/http/middleware/helmet.js +20 -0
  64. package/dist/http/middleware/rate-limit.d.ts +51 -0
  65. package/dist/http/middleware/rate-limit.d.ts.map +1 -0
  66. package/dist/http/middleware/rate-limit.js +46 -0
  67. package/dist/http/middleware/request-id.d.ts +5 -0
  68. package/dist/http/middleware/request-id.d.ts.map +1 -0
  69. package/dist/http/middleware/request-id.js +12 -0
  70. package/dist/http/middleware/request-logger.d.ts +27 -0
  71. package/dist/http/middleware/request-logger.d.ts.map +1 -0
  72. package/dist/http/middleware/request-logger.js +16 -0
  73. package/dist/http/middleware/session.d.ts +62 -0
  74. package/dist/http/middleware/session.d.ts.map +1 -0
  75. package/dist/http/middleware/session.js +76 -0
  76. package/dist/http/middleware/spa.d.ts +93 -0
  77. package/dist/http/middleware/spa.d.ts.map +1 -0
  78. package/dist/http/middleware/spa.js +52 -0
  79. package/dist/http/middleware/upload.d.ts +75 -0
  80. package/dist/http/middleware/upload.d.ts.map +1 -0
  81. package/dist/http/middleware/upload.js +119 -0
  82. package/dist/http/middleware/validate.d.ts +13 -0
  83. package/dist/http/middleware/validate.d.ts.map +1 -0
  84. package/dist/http/middleware/validate.js +45 -0
  85. package/dist/http/middleware/views.d.ts +56 -0
  86. package/dist/http/middleware/views.d.ts.map +1 -0
  87. package/dist/http/middleware/views.js +18 -0
  88. package/dist/http/query/index.d.ts +4 -0
  89. package/dist/http/query/index.d.ts.map +1 -0
  90. package/dist/http/query/index.js +10 -0
  91. package/dist/http/query/parse-query.d.ts +44 -0
  92. package/dist/http/query/parse-query.d.ts.map +1 -0
  93. package/dist/http/query/types.d.ts +100 -0
  94. package/dist/http/query/types.d.ts.map +1 -0
  95. package/dist/http/router-builder.d.ts +17 -0
  96. package/dist/http/router-builder.d.ts.map +1 -0
  97. package/dist/http/router-builder.js +37 -0
  98. package/dist/index.d.ts +23 -0
  99. package/dist/index.d.ts.map +1 -0
  100. package/dist/index.js +99 -0
  101. package/dist/query-Bym31XRp.js +88 -0
  102. package/package.json +90 -29
  103. package/index.d.ts +0 -3
  104. package/index.js +0 -13
@@ -0,0 +1,12 @@
1
+ function n(r) {
2
+ let e = r?.trim() || "";
3
+ return e === "/" ? "" : (e && !e.startsWith("/") && (e = `/${e}`), e = e.replace(/\/+$/, ""), e = e.replace(/\/\/+/g, "/"), e);
4
+ }
5
+ function i(...r) {
6
+ const e = ("/" + r.map((t) => t?.trim() || "").filter(Boolean).join("/")).replace(/\/\/+/g, "/");
7
+ return e === "/" ? "/" : e.replace(/\/+$/, "");
8
+ }
9
+ export {
10
+ i as joinPaths,
11
+ n as normalizePath
12
+ };
@@ -0,0 +1,90 @@
1
+ import type { Container } from './container';
2
+ import type { AppAdapter } from './adapter';
3
+ import type { AppModuleClass } from './app-module';
4
+ /**
5
+ * Plugin interface for extending KickJS applications.
6
+ *
7
+ * Plugins bundle modules, adapters, middleware, and DI bindings into a single
8
+ * reusable unit. They run before the application bootstraps, so they can
9
+ * register services and configure the app before any module loads.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import type { KickPlugin } from '@forinda/kickjs-core'
14
+ *
15
+ * export class CorsPlugin implements KickPlugin {
16
+ * name = 'CorsPlugin'
17
+ *
18
+ * middleware() {
19
+ * return [cors({ origin: '*' })]
20
+ * }
21
+ * }
22
+ *
23
+ * // Usage:
24
+ * bootstrap({
25
+ * modules,
26
+ * plugins: [new CorsPlugin()],
27
+ * })
28
+ * ```
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * // A more complex plugin that bundles modules and adapters
33
+ * export class AuthPlugin implements KickPlugin {
34
+ * name = 'AuthPlugin'
35
+ *
36
+ * constructor(private config: AuthConfig) {}
37
+ *
38
+ * register(container: Container) {
39
+ * container.registerFactory(AUTH_SERVICE, () => new JwtAuthService(this.config))
40
+ * }
41
+ *
42
+ * modules() {
43
+ * return [AuthModule]
44
+ * }
45
+ *
46
+ * adapters() {
47
+ * return [new AuthGuardAdapter(this.config)]
48
+ * }
49
+ *
50
+ * middleware() {
51
+ * return [passport.initialize()]
52
+ * }
53
+ * }
54
+ * ```
55
+ */
56
+ export interface KickPlugin {
57
+ /** Human-readable name for logging and debugging */
58
+ name: string;
59
+ /**
60
+ * Register DI bindings before modules load.
61
+ * Use this to provide services that modules depend on.
62
+ */
63
+ register?(container: Container): void;
64
+ /**
65
+ * Return module classes to be loaded alongside user modules.
66
+ * Plugin modules are loaded before user modules.
67
+ */
68
+ modules?(): AppModuleClass[];
69
+ /**
70
+ * Return adapter instances to be added to the application.
71
+ * Plugin adapters are added before user adapters.
72
+ */
73
+ adapters?(): AppAdapter[];
74
+ /**
75
+ * Return Express middleware to be added to the global pipeline.
76
+ * Plugin middleware runs before user-defined middleware.
77
+ */
78
+ middleware?(): any[];
79
+ /**
80
+ * Called after the application has fully bootstrapped.
81
+ * Use for post-startup logic like logging, health registration, etc.
82
+ */
83
+ onReady?(container: Container): void | Promise<void>;
84
+ /**
85
+ * Called during application shutdown.
86
+ * Clean up plugin resources (connections, intervals, etc.).
87
+ */
88
+ shutdown?(): void | Promise<void>;
89
+ }
90
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/core/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,MAAM,WAAW,UAAU;IACzB,oDAAoD;IACpD,IAAI,EAAE,MAAM,CAAA;IAEZ;;;OAGG;IACH,QAAQ,CAAC,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,CAAA;IAErC;;;OAGG;IACH,OAAO,CAAC,IAAI,cAAc,EAAE,CAAA;IAE5B;;;OAGG;IACH,QAAQ,CAAC,IAAI,UAAU,EAAE,CAAA;IAEzB;;;OAGG;IACH,UAAU,CAAC,IAAI,GAAG,EAAE,CAAA;IAEpB;;;OAGG;IACH,OAAO,CAAC,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAEpD;;;OAGG;IACH,QAAQ,CAAC,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAClC"}
File without changes
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Lightweight reactivity system inspired by Vue 3's composition API.
3
+ * Provides ref(), computed(), watch(), and reactive() for observable
4
+ * backend state — config, metrics, health, circuit breakers.
5
+ */
6
+ export interface Ref<T = any> {
7
+ value: T;
8
+ /** Subscribe to changes. Returns unsubscribe function. */
9
+ subscribe(fn: (newValue: T, oldValue: T) => void): () => void;
10
+ }
11
+ /**
12
+ * Create a reactive reference. Reading `.value` tracks the dependency,
13
+ * writing `.value` triggers watchers and computed recalculations.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const count = ref(0)
18
+ * count.value++ // triggers watchers
19
+ * ```
20
+ */
21
+ export declare function ref<T>(initialValue: T): Ref<T>;
22
+ export interface ComputedRef<T = any> {
23
+ readonly value: T;
24
+ }
25
+ /**
26
+ * Create a computed value that auto-recalculates when its reactive
27
+ * dependencies change. Cached until a dependency triggers.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const count = ref(0)
32
+ * const doubled = computed(() => count.value * 2)
33
+ * count.value = 5
34
+ * console.log(doubled.value) // 10
35
+ * ```
36
+ */
37
+ export declare function computed<T>(getter: () => T): ComputedRef<T>;
38
+ export interface WatchOptions {
39
+ /** Run the callback immediately with the current value (default: false) */
40
+ immediate?: boolean;
41
+ }
42
+ type WatchSource<T> = Ref<T> | ComputedRef<T> | (() => T);
43
+ /**
44
+ * Watch a reactive source and run a callback when it changes.
45
+ * Returns a stop function to unsubscribe.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const count = ref(0)
50
+ * const stop = watch(count, (newVal, oldVal) => {
51
+ * console.log(`Changed from ${oldVal} to ${newVal}`)
52
+ * })
53
+ * count.value = 1 // logs: "Changed from 0 to 1"
54
+ * stop() // no more callbacks
55
+ * ```
56
+ */
57
+ export declare function watch<T>(source: WatchSource<T>, callback: (newValue: T, oldValue: T) => void, options?: WatchOptions): () => void;
58
+ /**
59
+ * Create a deeply reactive proxy around a plain object. Property reads
60
+ * are tracked, property writes trigger watchers and computed recalculations.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * const state = reactive({ users: 0, errors: 0 })
65
+ * const errorRate = computed(() =>
66
+ * state.users > 0 ? state.errors / state.users : 0
67
+ * )
68
+ * state.users = 100
69
+ * state.errors = 5
70
+ * console.log(errorRate.value) // 0.05
71
+ * ```
72
+ */
73
+ export declare function reactive<T extends Record<string, any>>(target: T): T;
74
+ /** Check if a value is a Ref */
75
+ export declare function isRef(value: any): value is Ref;
76
+ /** Unwrap a ref or return the value as-is */
77
+ export declare function unref<T>(value: Ref<T> | T): T;
78
+ /** Convert all properties of an object to refs */
79
+ export declare function toRefs<T extends Record<string, any>>(obj: T): {
80
+ [K in keyof T]: Ref<T[K]>;
81
+ };
82
+ export {};
83
+ //# sourceMappingURL=reactivity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactivity.d.ts","sourceRoot":"","sources":["../../src/core/reactivity.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAmCH,MAAM,WAAW,GAAG,CAAC,CAAC,GAAG,GAAG;IAC1B,KAAK,EAAE,CAAC,CAAA;IACR,0DAA0D;IAC1D,SAAS,CAAC,EAAE,EAAE,CAAC,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAA;CAC9D;AAED;;;;;;;;;GASG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAuB9C;AAID,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IAClC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAClB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CA2B3D;AAID,MAAM,WAAW,YAAY;IAC3B,2EAA2E;IAC3E,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,KAAK,WAAW,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;AAEzD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,KAAK,CAAC,CAAC,EACrB,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACtB,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,IAAI,EAC5C,OAAO,CAAC,EAAE,YAAY,GACrB,MAAM,IAAI,CA+BZ;AAID;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAqBpE;AAID,gCAAgC;AAChC,wBAAgB,KAAK,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,GAAG,CAE9C;AAED,6CAA6C;AAC7C,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAE7C;AAED,kDAAkD;AAClD,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,CAM3F"}
@@ -0,0 +1,101 @@
1
+ var o = null, i = /* @__PURE__ */ new WeakMap();
2
+ function l(n, r) {
3
+ if (!o) return;
4
+ let e = i.get(n);
5
+ e || (e = /* @__PURE__ */ new Map(), i.set(n, e));
6
+ let t = e.get(r);
7
+ t || (t = /* @__PURE__ */ new Set(), e.set(r, t)), t.add(o);
8
+ }
9
+ function a(n, r) {
10
+ const e = i.get(n);
11
+ if (!e) return;
12
+ const t = e.get(r);
13
+ if (t)
14
+ for (const u of t) u();
15
+ }
16
+ function d(n) {
17
+ const r = /* @__PURE__ */ new Set(), e = { _value: n };
18
+ return {
19
+ get value() {
20
+ return l(e, "_value"), e._value;
21
+ },
22
+ set value(t) {
23
+ const u = e._value;
24
+ if (!Object.is(u, t)) {
25
+ e._value = t, a(e, "_value");
26
+ for (const f of r) f(t, u);
27
+ }
28
+ },
29
+ subscribe(t) {
30
+ return r.add(t), () => r.delete(t);
31
+ }
32
+ };
33
+ }
34
+ function y(n) {
35
+ let r, e = !0;
36
+ const t = { _value: void 0 }, u = () => {
37
+ e = !0, a(t, "_value");
38
+ };
39
+ return { get value() {
40
+ if (l(t, "_value"), e) {
41
+ const f = o;
42
+ o = u;
43
+ try {
44
+ r = n();
45
+ } finally {
46
+ o = f;
47
+ }
48
+ t._value = r, e = !1;
49
+ }
50
+ return r;
51
+ } };
52
+ }
53
+ function _(n, r, e) {
54
+ let t, u = !1;
55
+ const f = typeof n == "function" ? n : () => n.value, s = () => {
56
+ if (u) return;
57
+ const c = f();
58
+ Object.is(c, t) || (r(c, t), t = c);
59
+ }, p = o;
60
+ o = s;
61
+ try {
62
+ t = f();
63
+ } finally {
64
+ o = p;
65
+ }
66
+ return e?.immediate && r(t, void 0), () => {
67
+ u = !0;
68
+ };
69
+ }
70
+ function v(n) {
71
+ return new Proxy(n, {
72
+ get(r, e, t) {
73
+ const u = Reflect.get(r, e, t);
74
+ return typeof e == "symbol" ? u : (l(r, e), u !== null && typeof u == "object" && !Array.isArray(u) ? v(u) : u);
75
+ },
76
+ set(r, e, t, u) {
77
+ const f = Reflect.get(r, e, u), s = Reflect.set(r, e, t, u);
78
+ return !Object.is(f, t) && typeof e != "symbol" && a(r, e), s;
79
+ }
80
+ });
81
+ }
82
+ function g(n) {
83
+ return n !== null && typeof n == "object" && "subscribe" in n && "value" in n;
84
+ }
85
+ function b(n) {
86
+ return g(n) ? n.value : n;
87
+ }
88
+ function w(n) {
89
+ const r = {};
90
+ for (const e in n) r[e] = d(n[e]);
91
+ return r;
92
+ }
93
+ export {
94
+ y as computed,
95
+ g as isRef,
96
+ v as reactive,
97
+ d as ref,
98
+ w as toRefs,
99
+ b as unref,
100
+ _ as watch
101
+ };
@@ -0,0 +1,7 @@
1
+ import "./core/interfaces.js";
2
+ import "./core/container.js";
3
+ import "./core/decorators.js";
4
+ import "./core/cron.js";
5
+ import "./core/cache.js";
6
+ import "./core/logger.js";
7
+ import "reflect-metadata";
@@ -0,0 +1,103 @@
1
+ import http from 'node:http';
2
+ import { type Express, type RequestHandler } from 'express';
3
+ import { type AppModuleClass, type AppAdapter, type KickPlugin } from '../core';
4
+ /**
5
+ * A middleware entry in the declarative pipeline.
6
+ * Can be a bare handler or an object with path scoping.
7
+ */
8
+ export type MiddlewareEntry = RequestHandler | {
9
+ path: string;
10
+ handler: RequestHandler;
11
+ };
12
+ export interface ApplicationOptions {
13
+ /** Feature modules to load */
14
+ modules: AppModuleClass[];
15
+ /** Adapters that hook into the lifecycle (DB, Redis, Swagger, etc.) */
16
+ adapters?: AppAdapter[];
17
+ /** Server port (falls back to PORT env var, then 3000) */
18
+ port?: number;
19
+ /** Global API prefix (default: '/api') */
20
+ apiPrefix?: string;
21
+ /** Default API version (default: 1) — routes become /{prefix}/v{version}/{path} */
22
+ defaultVersion?: number;
23
+ /**
24
+ * Global middleware pipeline. Declared in order.
25
+ * Replaces the hardcoded middleware stack — you control exactly what runs.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * bootstrap({
30
+ * modules,
31
+ * middleware: [
32
+ * helmet(),
33
+ * cors(),
34
+ * compression(),
35
+ * morgan('dev'),
36
+ * express.json({ limit: '1mb' }),
37
+ * ],
38
+ * })
39
+ * ```
40
+ *
41
+ * If omitted, a sensible default is applied:
42
+ * requestId(), express.json({ limit: '100kb' })
43
+ */
44
+ middleware?: MiddlewareEntry[];
45
+ /** Plugins that bundle modules, adapters, middleware, and DI bindings */
46
+ plugins?: KickPlugin[];
47
+ /** Express `trust proxy` setting */
48
+ trustProxy?: boolean | number | string | ((ip: string, hopIndex: number) => boolean);
49
+ /** Maximum JSON body size (only used when middleware is not provided) */
50
+ jsonLimit?: string | number;
51
+ /**
52
+ * Log route summary on startup. Default: true in dev, false in production.
53
+ * Set to `true` to always log, `false` to always suppress.
54
+ */
55
+ logRoutesTable?: boolean;
56
+ }
57
+ /**
58
+ * The main application class. Wires together Express, the DI container,
59
+ * feature modules, adapters, and the middleware pipeline.
60
+ */
61
+ export declare class Application {
62
+ private readonly options;
63
+ private app;
64
+ private container;
65
+ private httpServer;
66
+ private adapters;
67
+ private plugins;
68
+ constructor(options: ApplicationOptions);
69
+ /**
70
+ * Full setup pipeline:
71
+ * 1. Adapter beforeMount hooks (early routes — docs, health)
72
+ * 2. Adapter middleware (phase: beforeGlobal)
73
+ * 3. Global middleware (user-declared or defaults)
74
+ * 4. Adapter middleware (phase: afterGlobal)
75
+ * 5. Module registration + DI bootstrap
76
+ * 6. Adapter middleware (phase: beforeRoutes)
77
+ * 7. Module route mounting
78
+ * 8. Adapter middleware (phase: afterRoutes)
79
+ * 9. Error handlers (notFound + global)
80
+ * 10. Adapter beforeStart hooks
81
+ */
82
+ /** Build the adapter context object (shared across all hooks) */
83
+ private adapterCtx;
84
+ /** Call an adapter hook, catching sync errors and async rejections */
85
+ private callHook;
86
+ setup(): void;
87
+ /** Register modules and DI without starting the HTTP server (used by kick tinker) */
88
+ registerOnly(): void;
89
+ /** Start the HTTP server — fails fast if port is in use */
90
+ start(): void;
91
+ /** HMR rebuild: swap Express handler without restarting the server */
92
+ rebuild(): void;
93
+ /** Graceful shutdown — runs all adapter shutdowns in parallel, resilient to failures */
94
+ shutdown(): Promise<void>;
95
+ getExpressApp(): Express;
96
+ /** Get registered adapters — used by DevToolsAdapter for peer discovery */
97
+ getAdapters(): AppAdapter[];
98
+ getHttpServer(): http.Server | null;
99
+ private collectAdapterMiddleware;
100
+ private mountMiddlewareList;
101
+ private mountMiddlewareEntry;
102
+ }
103
+ //# sourceMappingURL=application.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../../src/http/application.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAgB,EAAE,KAAK,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAA;AACpE,OAAO,EAKL,KAAK,cAAc,EACnB,KAAK,UAAU,EAGf,KAAK,UAAU,EAEhB,MAAM,SAAS,CAAA;AAMhB;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,cAAc,CAAA;CAAE,CAAA;AAExF,MAAM,WAAW,kBAAkB;IACjC,8BAA8B;IAC9B,OAAO,EAAE,cAAc,EAAE,CAAA;IACzB,uEAAuE;IACvE,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAA;IACvB,0DAA0D;IAC1D,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,mFAAmF;IACnF,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,UAAU,CAAC,EAAE,eAAe,EAAE,CAAA;IAE9B,yEAAyE;IACzE,OAAO,CAAC,EAAE,UAAU,EAAE,CAAA;IAEtB,oCAAoC;IACpC,UAAU,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,CAAA;IACpF,yEAAyE;IACzE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC3B;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED;;;GAGG;AACH,qBAAa,WAAW;IAQV,OAAO,CAAC,QAAQ,CAAC,OAAO;IAPpC,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,SAAS,CAAW;IAC5B,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,QAAQ,CAAc;IAE9B,OAAO,CAAC,OAAO,CAAc;gBAEA,OAAO,EAAE,kBAAkB;IAWxD;;;;;;;;;;;;OAYG;IACH,iEAAiE;IACjE,OAAO,CAAC,UAAU;IAWlB,sEAAsE;IACtE,OAAO,CAAC,QAAQ;IAgBhB,KAAK,IAAI,IAAI;IAgJb,qFAAqF;IACrF,YAAY,IAAI,IAAI;IAIpB,2DAA2D;IAC3D,KAAK,IAAI,IAAI;IAkCb,sEAAsE;IACtE,OAAO,IAAI,IAAI;IAef,wFAAwF;IAClF,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAmB/B,aAAa,IAAI,OAAO;IAIxB,2EAA2E;IAC3E,WAAW,IAAI,UAAU,EAAE;IAI3B,aAAa,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI;IAMnC,OAAO,CAAC,wBAAwB;IAmBhC,OAAO,CAAC,mBAAmB;IAU3B,OAAO,CAAC,oBAAoB;CAO7B"}
@@ -0,0 +1,167 @@
1
+ import { METADATA as A } from "../core/interfaces.js";
2
+ import { Container as m } from "../core/container.js";
3
+ import { createLogger as E } from "../core/logger.js";
4
+ import { normalizePath as P } from "../core/path.js";
5
+ import "../core-B6Okew3W.js";
6
+ import { requestId as R } from "./middleware/request-id.js";
7
+ import { errorHandler as x, notFoundHandler as M } from "./middleware/error-handler.js";
8
+ import y from "node:http";
9
+ import g from "express";
10
+ var n = E("Application"), G = class {
11
+ app;
12
+ container;
13
+ httpServer = null;
14
+ adapters;
15
+ plugins;
16
+ constructor(e) {
17
+ this.options = e, this.app = g(), this.container = m.getInstance(), this.plugins = e.plugins ?? [], this.adapters = [...this.plugins.flatMap((t) => t.adapters?.() ?? []), ...e.adapters ?? []];
18
+ }
19
+ adapterCtx(e) {
20
+ const t = process.env.NODE_ENV ?? "development";
21
+ return {
22
+ app: this.app,
23
+ container: this.container,
24
+ server: e,
25
+ env: t,
26
+ isProduction: t === "production"
27
+ };
28
+ }
29
+ callHook(e, t) {
30
+ if (e)
31
+ try {
32
+ const r = e(t);
33
+ r && typeof r.catch == "function" && r.catch((p) => n.error(p, "Adapter async hook failed"));
34
+ } catch (r) {
35
+ n.error(r, "Adapter hook failed");
36
+ }
37
+ }
38
+ setup() {
39
+ n.info("Bootstrapping application...");
40
+ const e = this.collectAdapterMiddleware();
41
+ this.app.__kickApp = this;
42
+ const t = this.adapterCtx();
43
+ for (const o of this.adapters) this.callHook(o.beforeMount?.bind(o), t);
44
+ this.app.disable("x-powered-by"), this.app.set("trust proxy", this.options.trustProxy ?? !1), this.mountMiddlewareList(e.beforeGlobal);
45
+ for (const o of this.plugins) o.register?.(this.container);
46
+ for (const o of this.plugins) {
47
+ const s = o.middleware?.() ?? [];
48
+ for (const l of s) this.app.use(l);
49
+ }
50
+ if (this.options.middleware) for (const o of this.options.middleware) this.mountMiddlewareEntry(o);
51
+ else
52
+ this.app.use(R()), this.app.use(g.json({ limit: this.options.jsonLimit ?? "100kb" }));
53
+ this.mountMiddlewareList(e.afterGlobal);
54
+ const r = [...this.plugins.flatMap((o) => o.modules?.() ?? []), ...this.options.modules].map((o) => {
55
+ const s = new o();
56
+ return s.register(this.container), s;
57
+ });
58
+ this.container.bootstrap(), this.mountMiddlewareList(e.beforeRoutes);
59
+ const p = this.options.apiPrefix ?? "/api", v = this.options.defaultVersion ?? 1, w = this.options.logRoutesTable ?? process.env.NODE_ENV !== "production", u = [];
60
+ for (const o of r) {
61
+ const s = o.routes();
62
+ if (!s) continue;
63
+ const l = Array.isArray(s) ? s : [s];
64
+ for (const i of l) {
65
+ const a = `${p}/v${i.version ?? v}${P(i.path)}`;
66
+ if (this.app.use(a, i.router), i.controller) {
67
+ for (const h of this.adapters) h.onRouteMount?.(i.controller, a);
68
+ w && u.push({
69
+ controller: i.controller,
70
+ mountPath: a
71
+ });
72
+ }
73
+ }
74
+ }
75
+ if (w && u.length > 0) {
76
+ const o = [
77
+ "GET",
78
+ "POST",
79
+ "PUT",
80
+ "PATCH",
81
+ "DELETE",
82
+ "HEAD",
83
+ "OPTIONS"
84
+ ], s = (i) => {
85
+ const a = o.indexOf(i);
86
+ return a === -1 ? 99 : a;
87
+ };
88
+ let l = 0;
89
+ n.info("Routes:");
90
+ for (const { controller: i, mountPath: a } of u) {
91
+ const h = Reflect.getMetadata(A.ROUTES, i) || [];
92
+ if (h.length === 0) continue;
93
+ const f = {};
94
+ for (const c of h) {
95
+ const d = c.method.toUpperCase();
96
+ f[d] = (f[d] || 0) + 1;
97
+ }
98
+ l += h.length;
99
+ const S = Object.entries(f).sort(([c], [d]) => s(c) - s(d)).map(([c, d]) => `${d} ${c}`).join(", "), b = i.name || "Controller";
100
+ n.info(` ${b.padEnd(30)} ${a.padEnd(25)} ${h.length} routes (${S})`);
101
+ }
102
+ n.info(` Total: ${l} routes`);
103
+ }
104
+ this.mountMiddlewareList(e.afterRoutes), this.app.use(M()), this.app.use(x());
105
+ for (const o of this.adapters) this.callHook(o.beforeStart?.bind(o), t);
106
+ }
107
+ registerOnly() {
108
+ this.setup();
109
+ }
110
+ start() {
111
+ this.setup();
112
+ const e = this.options.port ?? parseInt(process.env.PORT || "3000", 10);
113
+ this.httpServer = y.createServer(this.app), this.httpServer.on("error", (t) => {
114
+ throw t.code === "EADDRINUSE" && (n.error(`Port ${e} is already in use. Kill the existing process or use a different port:
115
+ PORT=${e + 1} kick dev
116
+ lsof -i :${e} # find what's using it
117
+ kill <PID> # stop it`), process.exit(1)), t;
118
+ }), this.httpServer.listen(e, async () => {
119
+ n.info(`Server running on http://localhost:${e}`);
120
+ for (const t of this.adapters) {
121
+ const r = this.adapterCtx(this.httpServer);
122
+ this.callHook(t.afterStart?.bind(t), r);
123
+ }
124
+ for (const t of this.plugins) await t.onReady?.(this.container);
125
+ });
126
+ }
127
+ rebuild() {
128
+ m.reset(), this.container = m.getInstance(), this.app = g(), this.setup(), this.httpServer && (this.httpServer.removeAllListeners("request"), this.httpServer.on("request", this.app), n.info("HMR: Express app rebuilt and swapped"));
129
+ }
130
+ async shutdown() {
131
+ n.info("Shutting down...");
132
+ const e = await Promise.allSettled([...this.plugins.map((t) => Promise.resolve(t.shutdown?.())), ...this.adapters.map((t) => Promise.resolve(t.shutdown?.()))]);
133
+ for (const t of e) t.status === "rejected" && n.error({ err: t.reason }, "Adapter shutdown failed");
134
+ this.httpServer && await new Promise((t) => this.httpServer.close(() => t()));
135
+ }
136
+ getExpressApp() {
137
+ return this.app;
138
+ }
139
+ getAdapters() {
140
+ return this.adapters;
141
+ }
142
+ getHttpServer() {
143
+ return this.httpServer;
144
+ }
145
+ collectAdapterMiddleware() {
146
+ const e = {
147
+ beforeGlobal: [],
148
+ afterGlobal: [],
149
+ beforeRoutes: [],
150
+ afterRoutes: []
151
+ };
152
+ for (const t of this.adapters) {
153
+ const r = t.middleware?.() ?? [];
154
+ for (const p of r) e[p.phase ?? "afterGlobal"].push(p);
155
+ }
156
+ return e;
157
+ }
158
+ mountMiddlewareList(e) {
159
+ for (const t of e) t.path ? this.app.use(t.path, t.handler) : this.app.use(t.handler);
160
+ }
161
+ mountMiddlewareEntry(e) {
162
+ typeof e == "function" ? this.app.use(e) : this.app.use(e.path, e.handler);
163
+ }
164
+ };
165
+ export {
166
+ G as Application
167
+ };
@@ -0,0 +1,22 @@
1
+ import { type ApplicationOptions } from './application';
2
+ /**
3
+ * Bootstrap a KickJS application with zero boilerplate.
4
+ *
5
+ * Handles:
6
+ * - Vite HMR (hot-swaps Express handler without restarting the server)
7
+ * - Graceful shutdown on SIGINT / SIGTERM
8
+ * - Global uncaughtException / unhandledRejection handlers
9
+ * - globalThis app storage for HMR rebuild
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * // src/index.ts — that's it, the whole file
14
+ * import 'reflect-metadata'
15
+ * import { bootstrap } from '@forinda/kickjs-http'
16
+ * import { modules } from './modules'
17
+ *
18
+ * bootstrap({ modules })
19
+ * ```
20
+ */
21
+ export declare function bootstrap(options: ApplicationOptions): void;
22
+ //# sourceMappingURL=bootstrap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../src/http/bootstrap.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAcpE;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAiD3D"}
@@ -0,0 +1,40 @@
1
+ import { t as p } from "../chunk-DVVP7zzD.js";
2
+ import { createLogger as a } from "../core/logger.js";
3
+ import "../core-B6Okew3W.js";
4
+ import { Application as c } from "./application.js";
5
+ function s() {
6
+ try {
7
+ p("@forinda/kickjs-config").reloadEnv?.();
8
+ } catch {
9
+ }
10
+ }
11
+ var r = a("Process");
12
+ function l(i) {
13
+ const o = globalThis;
14
+ if (!o.__kickBootstrapped) {
15
+ process.on("uncaughtException", (t) => {
16
+ r.error(t, "Uncaught exception");
17
+ }), process.on("unhandledRejection", (t) => {
18
+ r.error(t, "Unhandled rejection");
19
+ });
20
+ for (const t of ["SIGINT", "SIGTERM"]) process.on(t, async () => {
21
+ r.info(`Received ${t}, shutting down...`), o.__app && await o.__app.shutdown(), process.exit(0);
22
+ });
23
+ o.__kickBootstrapped = !0;
24
+ }
25
+ if (o.__app) {
26
+ r.info("HMR: Rebuilding application..."), s(), o.__app.rebuild();
27
+ return;
28
+ }
29
+ const e = new c(i);
30
+ if (o.__app = e, process.env.KICK_TINKER) {
31
+ e.registerOnly();
32
+ return;
33
+ }
34
+ e.start();
35
+ const n = import.meta;
36
+ n.hot && n.hot.accept();
37
+ }
38
+ export {
39
+ l as bootstrap
40
+ };