@forinda/kickjs 2.0.0 → 2.1.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 (237) hide show
  1. package/README.md +85 -584
  2. package/dist/adapter-BqGjZCSm.d.mts +122 -0
  3. package/dist/adapter-BqGjZCSm.d.mts.map +1 -0
  4. package/dist/app-module-CcEbAVtB.d.mts +33 -0
  5. package/dist/app-module-CcEbAVtB.d.mts.map +1 -0
  6. package/dist/application-DNHj-_UL.mjs +449 -0
  7. package/dist/application-DNHj-_UL.mjs.map +1 -0
  8. package/dist/bootstrap-DLEZaJ3b.mjs +205 -0
  9. package/dist/bootstrap-DLEZaJ3b.mjs.map +1 -0
  10. package/dist/{core/cache.d.ts → cache-DJeMaGqb.d.mts} +33 -31
  11. package/dist/cache-DJeMaGqb.d.mts.map +1 -0
  12. package/dist/chunk-C5Qp-JxE.mjs +15 -0
  13. package/dist/container-nBSIhyqV.d.mts +141 -0
  14. package/dist/container-nBSIhyqV.d.mts.map +1 -0
  15. package/dist/core/adapter.d.mts +3 -0
  16. package/dist/core/adapter.mjs +11 -0
  17. package/dist/core/app-module.d.mts +3 -0
  18. package/dist/core/app-module.mjs +11 -0
  19. package/dist/core/cache.d.mts +3 -0
  20. package/dist/core/cache.mjs +113 -0
  21. package/dist/core/cache.mjs.map +1 -0
  22. package/dist/core/container.d.mts +3 -0
  23. package/dist/core/container.mjs +426 -0
  24. package/dist/core/container.mjs.map +1 -0
  25. package/dist/core/cron.d.mts +3 -0
  26. package/dist/core/cron.mjs +42 -0
  27. package/dist/core/cron.mjs.map +1 -0
  28. package/dist/core/decorators.d.mts +3 -0
  29. package/dist/core/decorators.mjs +213 -0
  30. package/dist/core/decorators.mjs.map +1 -0
  31. package/dist/core/errors.d.mts +3 -0
  32. package/dist/core/errors.mjs +97 -0
  33. package/dist/core/errors.mjs.map +1 -0
  34. package/dist/core/interfaces.d.mts +3 -0
  35. package/dist/core/interfaces.mjs +44 -0
  36. package/dist/core/interfaces.mjs.map +1 -0
  37. package/dist/core/logger.d.mts +3 -0
  38. package/dist/core/logger.mjs +217 -0
  39. package/dist/core/logger.mjs.map +1 -0
  40. package/dist/core/path.d.mts +3 -0
  41. package/dist/core/path.mjs +45 -0
  42. package/dist/core/path.mjs.map +1 -0
  43. package/dist/core/plugin.d.mts +3 -0
  44. package/dist/core/plugin.mjs +11 -0
  45. package/dist/core/reactivity.d.mts +3 -0
  46. package/dist/core/reactivity.mjs +189 -0
  47. package/dist/core/reactivity.mjs.map +1 -0
  48. package/dist/core-BL_H8fEZ.mjs +121 -0
  49. package/dist/core-BL_H8fEZ.mjs.map +1 -0
  50. package/dist/{core/cron.d.ts → cron-RKhH5TOd.d.mts} +16 -14
  51. package/dist/cron-RKhH5TOd.d.mts.map +1 -0
  52. package/dist/decorators-CQ93ak6Z.d.mts +154 -0
  53. package/dist/decorators-CQ93ak6Z.d.mts.map +1 -0
  54. package/dist/errors-te5Km00o.d.mts +68 -0
  55. package/dist/errors-te5Km00o.d.mts.map +1 -0
  56. package/dist/http/application.d.mts +220 -0
  57. package/dist/http/application.d.mts.map +1 -0
  58. package/dist/http/application.mjs +12 -0
  59. package/dist/http/bootstrap.d.mts +43 -0
  60. package/dist/http/bootstrap.d.mts.map +1 -0
  61. package/dist/http/bootstrap.mjs +12 -0
  62. package/dist/http/context.d.mts +131 -0
  63. package/dist/http/context.d.mts.map +1 -0
  64. package/dist/http/context.mjs +220 -0
  65. package/dist/http/context.mjs.map +1 -0
  66. package/dist/http/middleware/cors.d.mts +48 -0
  67. package/dist/http/middleware/cors.d.mts.map +1 -0
  68. package/dist/http/middleware/cors.mjs +83 -0
  69. package/dist/http/middleware/cors.mjs.map +1 -0
  70. package/dist/http/middleware/csrf.d.mts +52 -0
  71. package/dist/http/middleware/csrf.d.mts.map +1 -0
  72. package/dist/http/middleware/csrf.mjs +72 -0
  73. package/dist/http/middleware/csrf.mjs.map +1 -0
  74. package/dist/http/middleware/error-handler.d.mts +11 -0
  75. package/dist/http/middleware/error-handler.d.mts.map +1 -0
  76. package/dist/http/middleware/error-handler.mjs +52 -0
  77. package/dist/http/middleware/error-handler.mjs.map +1 -0
  78. package/dist/http/middleware/helmet.d.mts +41 -0
  79. package/dist/http/middleware/helmet.d.mts.map +1 -0
  80. package/dist/http/middleware/helmet.mjs +51 -0
  81. package/dist/http/middleware/helmet.mjs.map +1 -0
  82. package/dist/http/middleware/rate-limit.d.mts +56 -0
  83. package/dist/http/middleware/rate-limit.d.mts.map +1 -0
  84. package/dist/http/middleware/rate-limit.mjs +101 -0
  85. package/dist/http/middleware/rate-limit.mjs.map +1 -0
  86. package/dist/http/middleware/request-id.d.mts +10 -0
  87. package/dist/http/middleware/request-id.d.mts.map +1 -0
  88. package/dist/http/middleware/request-id.mjs +26 -0
  89. package/dist/http/middleware/request-id.mjs.map +1 -0
  90. package/dist/http/middleware/request-logger.d.mts +32 -0
  91. package/dist/http/middleware/request-logger.d.mts.map +1 -0
  92. package/dist/http/middleware/request-logger.mjs +49 -0
  93. package/dist/http/middleware/request-logger.mjs.map +1 -0
  94. package/dist/http/middleware/session.d.mts +67 -0
  95. package/dist/http/middleware/session.d.mts.map +1 -0
  96. package/dist/http/middleware/session.mjs +152 -0
  97. package/dist/http/middleware/session.mjs.map +1 -0
  98. package/dist/http/middleware/spa.d.mts +101 -0
  99. package/dist/http/middleware/spa.d.mts.map +1 -0
  100. package/dist/http/middleware/spa.mjs +108 -0
  101. package/dist/http/middleware/spa.mjs.map +1 -0
  102. package/dist/http/middleware/{upload.d.ts → upload.d.mts} +21 -17
  103. package/dist/http/middleware/upload.d.mts.map +1 -0
  104. package/dist/http/middleware/upload.mjs +191 -0
  105. package/dist/http/middleware/upload.mjs.map +1 -0
  106. package/dist/http/middleware/validate.d.mts +18 -0
  107. package/dist/http/middleware/validate.d.mts.map +1 -0
  108. package/dist/http/middleware/validate.mjs +62 -0
  109. package/dist/http/middleware/validate.mjs.map +1 -0
  110. package/dist/http/middleware/views.d.mts +62 -0
  111. package/dist/http/middleware/views.d.mts.map +1 -0
  112. package/dist/http/middleware/views.mjs +65 -0
  113. package/dist/http/middleware/views.mjs.map +1 -0
  114. package/dist/http/query/index.d.mts +3 -0
  115. package/dist/http/query/index.mjs +12 -0
  116. package/dist/http/{router-builder.d.ts → router-builder.d.mts} +9 -5
  117. package/dist/http/router-builder.d.mts.map +1 -0
  118. package/dist/http/router-builder.mjs +67 -0
  119. package/dist/http/router-builder.mjs.map +1 -0
  120. package/dist/index-C0gbnpSg.d.mts +107 -0
  121. package/dist/index-C0gbnpSg.d.mts.map +1 -0
  122. package/dist/index-Cls52etj.d.mts +148 -0
  123. package/dist/index-Cls52etj.d.mts.map +1 -0
  124. package/dist/index.d.mts +133 -0
  125. package/dist/index.d.mts.map +1 -0
  126. package/dist/index.mjs +126 -0
  127. package/dist/index.mjs.map +1 -0
  128. package/dist/interfaces-D-48zotH.d.mts +52 -0
  129. package/dist/interfaces-D-48zotH.d.mts.map +1 -0
  130. package/dist/logger-Dzj-TF0t.d.mts +119 -0
  131. package/dist/logger-Dzj-TF0t.d.mts.map +1 -0
  132. package/dist/metadata-fmvikBA0.mjs +76 -0
  133. package/dist/metadata-fmvikBA0.mjs.map +1 -0
  134. package/dist/{core/path.d.ts → path-LmwfhfyH.d.mts} +7 -3
  135. package/dist/path-LmwfhfyH.d.mts.map +1 -0
  136. package/dist/plugin-DIoPIpSm.d.mts +95 -0
  137. package/dist/plugin-DIoPIpSm.d.mts.map +1 -0
  138. package/dist/query-7cdHF6ry.mjs +164 -0
  139. package/dist/query-7cdHF6ry.mjs.map +1 -0
  140. package/dist/{core/reactivity.d.ts → reactivity-BbS-99ow.d.mts} +21 -20
  141. package/dist/reactivity-BbS-99ow.d.mts.map +1 -0
  142. package/package.json +73 -43
  143. package/dist/chunk-DVVP7zzD.js +0 -7
  144. package/dist/core/adapter.d.ts +0 -109
  145. package/dist/core/adapter.d.ts.map +0 -1
  146. package/dist/core/adapter.js +0 -0
  147. package/dist/core/app-module.d.ts +0 -28
  148. package/dist/core/app-module.d.ts.map +0 -1
  149. package/dist/core/app-module.js +0 -0
  150. package/dist/core/cache.d.ts.map +0 -1
  151. package/dist/core/cache.js +0 -57
  152. package/dist/core/container.d.ts +0 -63
  153. package/dist/core/container.d.ts.map +0 -1
  154. package/dist/core/container.js +0 -117
  155. package/dist/core/cron.d.ts.map +0 -1
  156. package/dist/core/cron.js +0 -22
  157. package/dist/core/decorators.d.ts +0 -153
  158. package/dist/core/decorators.d.ts.map +0 -1
  159. package/dist/core/decorators.js +0 -141
  160. package/dist/core/errors.d.ts +0 -64
  161. package/dist/core/errors.d.ts.map +0 -1
  162. package/dist/core/errors.js +0 -67
  163. package/dist/core/index.d.ts +0 -14
  164. package/dist/core/index.d.ts.map +0 -1
  165. package/dist/core/interfaces.d.ts +0 -44
  166. package/dist/core/interfaces.d.ts.map +0 -1
  167. package/dist/core/interfaces.js +0 -25
  168. package/dist/core/logger.d.ts +0 -43
  169. package/dist/core/logger.d.ts.map +0 -1
  170. package/dist/core/logger.js +0 -54
  171. package/dist/core/path.d.ts.map +0 -1
  172. package/dist/core/path.js +0 -12
  173. package/dist/core/plugin.d.ts +0 -90
  174. package/dist/core/plugin.d.ts.map +0 -1
  175. package/dist/core/plugin.js +0 -0
  176. package/dist/core/reactivity.d.ts.map +0 -1
  177. package/dist/core/reactivity.js +0 -101
  178. package/dist/core-B6Okew3W.js +0 -7
  179. package/dist/http/application.d.ts +0 -103
  180. package/dist/http/application.d.ts.map +0 -1
  181. package/dist/http/application.js +0 -167
  182. package/dist/http/bootstrap.d.ts +0 -22
  183. package/dist/http/bootstrap.d.ts.map +0 -1
  184. package/dist/http/bootstrap.js +0 -40
  185. package/dist/http/context.d.ts +0 -129
  186. package/dist/http/context.d.ts.map +0 -1
  187. package/dist/http/context.js +0 -115
  188. package/dist/http/index.d.ts +0 -16
  189. package/dist/http/index.d.ts.map +0 -1
  190. package/dist/http/middleware/cors.d.ts +0 -43
  191. package/dist/http/middleware/cors.d.ts.map +0 -1
  192. package/dist/http/middleware/cors.js +0 -31
  193. package/dist/http/middleware/csrf.d.ts +0 -47
  194. package/dist/http/middleware/csrf.d.ts.map +0 -1
  195. package/dist/http/middleware/csrf.js +0 -25
  196. package/dist/http/middleware/error-handler.d.ts +0 -6
  197. package/dist/http/middleware/error-handler.d.ts.map +0 -1
  198. package/dist/http/middleware/error-handler.js +0 -37
  199. package/dist/http/middleware/helmet.d.ts +0 -36
  200. package/dist/http/middleware/helmet.d.ts.map +0 -1
  201. package/dist/http/middleware/helmet.js +0 -20
  202. package/dist/http/middleware/rate-limit.d.ts +0 -51
  203. package/dist/http/middleware/rate-limit.d.ts.map +0 -1
  204. package/dist/http/middleware/rate-limit.js +0 -46
  205. package/dist/http/middleware/request-id.d.ts +0 -5
  206. package/dist/http/middleware/request-id.d.ts.map +0 -1
  207. package/dist/http/middleware/request-id.js +0 -12
  208. package/dist/http/middleware/request-logger.d.ts +0 -27
  209. package/dist/http/middleware/request-logger.d.ts.map +0 -1
  210. package/dist/http/middleware/request-logger.js +0 -16
  211. package/dist/http/middleware/session.d.ts +0 -62
  212. package/dist/http/middleware/session.d.ts.map +0 -1
  213. package/dist/http/middleware/session.js +0 -76
  214. package/dist/http/middleware/spa.d.ts +0 -93
  215. package/dist/http/middleware/spa.d.ts.map +0 -1
  216. package/dist/http/middleware/spa.js +0 -52
  217. package/dist/http/middleware/upload.d.ts.map +0 -1
  218. package/dist/http/middleware/upload.js +0 -119
  219. package/dist/http/middleware/validate.d.ts +0 -13
  220. package/dist/http/middleware/validate.d.ts.map +0 -1
  221. package/dist/http/middleware/validate.js +0 -45
  222. package/dist/http/middleware/views.d.ts +0 -56
  223. package/dist/http/middleware/views.d.ts.map +0 -1
  224. package/dist/http/middleware/views.js +0 -18
  225. package/dist/http/query/index.d.ts +0 -4
  226. package/dist/http/query/index.d.ts.map +0 -1
  227. package/dist/http/query/index.js +0 -10
  228. package/dist/http/query/parse-query.d.ts +0 -44
  229. package/dist/http/query/parse-query.d.ts.map +0 -1
  230. package/dist/http/query/types.d.ts +0 -100
  231. package/dist/http/query/types.d.ts.map +0 -1
  232. package/dist/http/router-builder.d.ts.map +0 -1
  233. package/dist/http/router-builder.js +0 -37
  234. package/dist/index.d.ts +0 -25
  235. package/dist/index.d.ts.map +0 -1
  236. package/dist/index.js +0 -103
  237. package/dist/query-Bym31XRp.js +0 -88
@@ -1,101 +0,0 @@
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
- };
@@ -1,7 +0,0 @@
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";
@@ -1,103 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,167 +0,0 @@
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
- };
@@ -1,22 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,40 +0,0 @@
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
- };
@@ -1,129 +0,0 @@
1
- import type { Request, Response, NextFunction } from 'express';
2
- import { type ParsedQuery, type QueryFieldConfig } from './query';
3
- /**
4
- * Unified request/response abstraction passed to every controller method.
5
- * Shields handlers from raw Express objects and provides convenience methods.
6
- */
7
- export declare class RequestContext<TBody = any, TParams = any, TQuery = any> {
8
- readonly req: Request;
9
- readonly res: Response;
10
- readonly next: NextFunction;
11
- constructor(req: Request, res: Response, next: NextFunction);
12
- /**
13
- * Per-request metadata map shared across all RequestContext instances
14
- * for the same request. Stored on `req` so middleware can pass data
15
- * to handlers via `ctx.set()` / `ctx.get()`.
16
- */
17
- private get metadata();
18
- get body(): TBody;
19
- get params(): TParams;
20
- get query(): TQuery;
21
- get headers(): import("node:http").IncomingHttpHeaders;
22
- get requestId(): string | undefined;
23
- /** Session data (requires session middleware) */
24
- get session(): any;
25
- /**
26
- * Parse the request query string into structured filters, sort, pagination, and search.
27
- * Pass the result to an ORM query builder adapter (Drizzle, Prisma, Sequelize, etc.).
28
- *
29
- * @param fieldConfig - Optional whitelist for filterable, sortable, and searchable fields
30
- *
31
- * @example
32
- * ```ts
33
- * @Get('/')
34
- * async list(ctx: RequestContext) {
35
- * const parsed = ctx.qs({
36
- * filterable: ['status', 'priority'],
37
- * sortable: ['createdAt', 'title'],
38
- * })
39
- * const q = drizzleAdapter.build(parsed, { columns })
40
- * // ... use q.where, q.orderBy, q.limit, q.offset
41
- * }
42
- * ```
43
- */
44
- qs(fieldConfig?: QueryFieldConfig): ParsedQuery;
45
- /** Single uploaded file (requires @FileUpload({ mode: 'single' })) */
46
- get file(): any;
47
- /** Array of uploaded files (requires @FileUpload({ mode: 'array' })) */
48
- get files(): any[] | undefined;
49
- get<T = any>(key: string): T | undefined;
50
- set(key: string, value: any): void;
51
- json(data: any, status?: number): Response<any, Record<string, any>>;
52
- created(data: any): Response<any, Record<string, any>>;
53
- noContent(): Response<any, Record<string, any>>;
54
- notFound(message?: string): Response<any, Record<string, any>>;
55
- badRequest(message: string): Response<any, Record<string, any>>;
56
- html(content: string, status?: number): Response<any, Record<string, any>>;
57
- download(buffer: Buffer, filename: string, contentType?: string): Response<any, Record<string, any>>;
58
- /**
59
- * Render a template using the registered view engine (EJS, Pug, Handlebars, etc.).
60
- * Requires a ViewAdapter to be configured in bootstrap().
61
- *
62
- * @param template - Template name (without extension, relative to viewsDir)
63
- * @param data - Data to pass to the template
64
- *
65
- * @example
66
- * ```ts
67
- * ctx.render('dashboard', { user, title: 'Dashboard' })
68
- * ctx.render('emails/welcome', { name: 'Alice' })
69
- * ```
70
- */
71
- render(template: string, data?: Record<string, any>): void;
72
- /**
73
- * Parse query params and return a standardized paginated response.
74
- * Calls `ctx.qs()` internally, then wraps your data with pagination meta.
75
- *
76
- * @param fetcher - Async function that receives ParsedQuery and returns `{ data, total }`
77
- * @param fieldConfig - Optional whitelist for filterable, sortable, searchable fields
78
- *
79
- * @example
80
- * ```ts
81
- * @Get('/')
82
- * async list(ctx: RequestContext) {
83
- * return ctx.paginate(
84
- * async (parsed) => {
85
- * const data = await db.select().from(users)
86
- * .where(query.where).limit(parsed.pagination.limit)
87
- * .offset(parsed.pagination.offset).all()
88
- * const total = await db.select({ count: count() }).from(users).get()
89
- * return { data, total: total?.count ?? 0 }
90
- * },
91
- * { filterable: ['name', 'role'], sortable: ['createdAt'] },
92
- * )
93
- * }
94
- * ```
95
- */
96
- paginate<T>(fetcher: (parsed: ParsedQuery) => Promise<{
97
- data: T[];
98
- total: number;
99
- }>, fieldConfig?: QueryFieldConfig): Promise<Response<any, Record<string, any>>>;
100
- /**
101
- * Start an SSE (Server-Sent Events) stream.
102
- * Sets the correct headers and returns helpers to send events.
103
- *
104
- * @example
105
- * ```ts
106
- * @Get('/events')
107
- * async stream(ctx: RequestContext) {
108
- * const sse = ctx.sse()
109
- *
110
- * const interval = setInterval(() => {
111
- * sse.send({ time: new Date().toISOString() }, 'tick')
112
- * }, 1000)
113
- *
114
- * sse.onClose(() => clearInterval(interval))
115
- * }
116
- * ```
117
- */
118
- sse(): {
119
- /** Send an SSE event with optional event name and id */
120
- send: (data: any, event?: string, id?: string) => void;
121
- /** Send a comment (keeps connection alive) */
122
- comment: (text: string) => void;
123
- /** Register a callback when the client disconnects */
124
- onClose: (fn: () => void) => void;
125
- /** End the SSE stream */
126
- close: () => void;
127
- };
128
- }
129
- //# sourceMappingURL=context.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/http/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC9D,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,gBAAgB,EAEtB,MAAM,SAAS,CAAA;AAEhB;;;GAGG;AACH,qBAAa,cAAc,CAAC,KAAK,GAAG,GAAG,EAAE,OAAO,GAAG,GAAG,EAAE,MAAM,GAAG,GAAG;aAEhD,GAAG,EAAE,OAAO;aACZ,GAAG,EAAE,QAAQ;aACb,IAAI,EAAE,YAAY;gBAFlB,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,YAAY;IAGpC;;;;OAIG;IACH,OAAO,KAAK,QAAQ,GAInB;IAID,IAAI,IAAI,IAAI,KAAK,CAEhB;IAED,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,IAAI,OAAO,4CAEV;IAED,IAAI,SAAS,IAAI,MAAM,GAAG,SAAS,CAElC;IAED,iDAAiD;IACjD,IAAI,OAAO,IAAI,GAAG,CAEjB;IAID;;;;;;;;;;;;;;;;;;OAkBG;IACH,EAAE,CAAC,WAAW,CAAC,EAAE,gBAAgB,GAAG,WAAW;IAM/C,sEAAsE;IACtE,IAAI,IAAI,IAAI,GAAG,CAEd;IAED,wEAAwE;IACxE,IAAI,KAAK,IAAI,GAAG,EAAE,GAAG,SAAS,CAE7B;IAID,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAIxC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAMlC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,SAAM;IAI5B,OAAO,CAAC,IAAI,EAAE,GAAG;IAIjB,SAAS;IAIT,QAAQ,CAAC,OAAO,SAAc;IAI9B,UAAU,CAAC,OAAO,EAAE,MAAM;IAI1B,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAM;IAIlC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,SAA6B;IAMnF;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM;IAIvD;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,QAAQ,CAAC,CAAC,EACd,OAAO,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,EACvE,WAAW,CAAC,EAAE,gBAAgB;IAwBhC;;;;;;;;;;;;;;;;;OAiBG;IACH,GAAG;QAgBC,wDAAwD;qBAC3C,GAAG,UAAU,MAAM,OAAO,MAAM;QAK7C,8CAA8C;wBAC9B,MAAM;QAGtB,sDAAsD;sBACxC,MAAM,IAAI;QAGxB,yBAAyB;;;CAM9B"}