@forinda/kickjs 5.3.0 → 5.4.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 (90) hide show
  1. package/dist/application-mir5CSWO.mjs +12 -0
  2. package/dist/{application-Cna_2gex.mjs.map → application-mir5CSWO.mjs.map} +1 -1
  3. package/dist/bootstrap-B7j_-dOg.mjs +12 -0
  4. package/dist/{bootstrap-kPcmbbWe.mjs.map → bootstrap-B7j_-dOg.mjs.map} +1 -1
  5. package/dist/config/index.mjs +2 -4
  6. package/dist/config-Dk5RVTnD.mjs +12 -0
  7. package/dist/{config-DxEREQmR.mjs.map → config-Dk5RVTnD.mjs.map} +1 -1
  8. package/dist/container-DArhTDQQ.mjs +12 -0
  9. package/dist/{container-SMnB5yeT.mjs.map → container-DArhTDQQ.mjs.map} +1 -1
  10. package/dist/{context-Ymvv-85x.d.mts → context-BAdAV-zO.d.mts} +48 -11
  11. package/dist/context-BAdAV-zO.d.mts.map +1 -0
  12. package/dist/context-CIoXqpAX.mjs +12 -0
  13. package/dist/context-CIoXqpAX.mjs.map +1 -0
  14. package/dist/core/adapter.mjs +2 -2
  15. package/dist/core/app-module.mjs +2 -2
  16. package/dist/core/cache.mjs +2 -103
  17. package/dist/core/cache.mjs.map +1 -1
  18. package/dist/core/container.mjs +2 -3
  19. package/dist/core/cron.mjs +2 -32
  20. package/dist/core/cron.mjs.map +1 -1
  21. package/dist/core/decorators.mjs +2 -285
  22. package/dist/core/decorators.mjs.map +1 -1
  23. package/dist/core/errors.mjs +2 -110
  24. package/dist/core/errors.mjs.map +1 -1
  25. package/dist/core/interfaces.mjs +2 -53
  26. package/dist/core/interfaces.mjs.map +1 -1
  27. package/dist/core/logger.mjs +2 -207
  28. package/dist/core/logger.mjs.map +1 -1
  29. package/dist/core/path.mjs +2 -35
  30. package/dist/core/path.mjs.map +1 -1
  31. package/dist/core/plugin.mjs +2 -2
  32. package/dist/core/reactivity.mjs +2 -179
  33. package/dist/core/reactivity.mjs.map +1 -1
  34. package/dist/core-BQZyB8Wv.mjs +12 -0
  35. package/dist/{core--a4XflX7.mjs.map → core-BQZyB8Wv.mjs.map} +1 -1
  36. package/dist/env-BL0xOTyi.mjs +12 -0
  37. package/dist/{env-C4Yr6nN8.mjs.map → env-BL0xOTyi.mjs.map} +1 -1
  38. package/dist/http/application.mjs +2 -3
  39. package/dist/http/bootstrap.mjs +2 -3
  40. package/dist/http/context.d.mts +2 -2
  41. package/dist/http/context.mjs +2 -3
  42. package/dist/http/middleware/cors.mjs +2 -73
  43. package/dist/http/middleware/cors.mjs.map +1 -1
  44. package/dist/http/middleware/csrf.mjs +2 -62
  45. package/dist/http/middleware/csrf.mjs.map +1 -1
  46. package/dist/http/middleware/error-handler.mjs +2 -54
  47. package/dist/http/middleware/error-handler.mjs.map +1 -1
  48. package/dist/http/middleware/helmet.mjs +2 -41
  49. package/dist/http/middleware/helmet.mjs.map +1 -1
  50. package/dist/http/middleware/rate-limit.mjs +2 -91
  51. package/dist/http/middleware/rate-limit.mjs.map +1 -1
  52. package/dist/http/middleware/request-id.mjs +2 -25
  53. package/dist/http/middleware/request-id.mjs.map +1 -1
  54. package/dist/http/middleware/request-logger.mjs +2 -39
  55. package/dist/http/middleware/request-logger.mjs.map +1 -1
  56. package/dist/http/middleware/session.mjs +2 -167
  57. package/dist/http/middleware/session.mjs.map +1 -1
  58. package/dist/http/middleware/spa.mjs +2 -98
  59. package/dist/http/middleware/spa.mjs.map +1 -1
  60. package/dist/http/middleware/upload.mjs +2 -181
  61. package/dist/http/middleware/upload.mjs.map +1 -1
  62. package/dist/http/middleware/validate.mjs +2 -68
  63. package/dist/http/middleware/validate.mjs.map +1 -1
  64. package/dist/http/middleware/views.d.mts +1 -1
  65. package/dist/http/middleware/views.mjs +2 -56
  66. package/dist/http/middleware/views.mjs.map +1 -1
  67. package/dist/http/query/index.mjs +2 -3
  68. package/dist/http/router-builder.mjs +2 -105
  69. package/dist/http/router-builder.mjs.map +1 -1
  70. package/dist/index.d.mts +3 -3
  71. package/dist/index.mjs +2 -171
  72. package/dist/index.mjs.map +1 -1
  73. package/dist/metadata-Dn6kNT82.mjs +12 -0
  74. package/dist/{metadata-CdYaU-XM.mjs.map → metadata-Dn6kNT82.mjs.map} +1 -1
  75. package/dist/query-B7n5isk_.mjs +12 -0
  76. package/dist/{query-nAYUgagU.mjs.map → query-B7n5isk_.mjs.map} +1 -1
  77. package/dist/{views-DkNp9JJs.d.mts → views-oKRSw0Op.d.mts} +2 -2
  78. package/dist/{views-DkNp9JJs.d.mts.map → views-oKRSw0Op.d.mts.map} +1 -1
  79. package/package.json +1 -1
  80. package/dist/application-Cna_2gex.mjs +0 -574
  81. package/dist/bootstrap-kPcmbbWe.mjs +0 -195
  82. package/dist/config-DxEREQmR.mjs +0 -135
  83. package/dist/container-SMnB5yeT.mjs +0 -897
  84. package/dist/context-B0B3WQft.mjs +0 -348
  85. package/dist/context-B0B3WQft.mjs.map +0 -1
  86. package/dist/context-Ymvv-85x.d.mts.map +0 -1
  87. package/dist/core--a4XflX7.mjs +0 -820
  88. package/dist/env-C4Yr6nN8.mjs +0 -137
  89. package/dist/metadata-CdYaU-XM.mjs +0 -76
  90. package/dist/query-nAYUgagU.mjs +0 -164
@@ -1,195 +0,0 @@
1
- /**
2
- * @forinda/kickjs v5.3.0
3
- *
4
- * Copyright (c) Felix Orinda
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- import { t as Container } from "./container-SMnB5yeT.mjs";
12
- import { createLogger } from "./core/logger.mjs";
13
- import "./core--a4XflX7.mjs";
14
- import { reactive, ref } from "./core/reactivity.mjs";
15
- import { t as Application } from "./application-Cna_2gex.mjs";
16
- import { a as reloadEnv } from "./env-C4Yr6nN8.mjs";
17
- import cluster from "node:cluster";
18
- import os from "node:os";
19
- //#region src/http/cluster.ts
20
- const log$1 = createLogger("Cluster");
21
- /** Returns true if the current process is the cluster primary */
22
- function isClusterPrimary() {
23
- return cluster.isPrimary;
24
- }
25
- /**
26
- * Fork worker processes and manage the cluster lifecycle.
27
- *
28
- * The primary process forks `workers` child processes. Each worker
29
- * shares the same port via Node's built-in `cluster` module (OS
30
- * round-robin load balancing).
31
- *
32
- * Features:
33
- * - Graceful shutdown with timeout fallback to forceful kill
34
- * - Auto-restart dead workers (respects voluntary disconnects)
35
- * - Startup timeout detection (stuck workers)
36
- * - Crash loop prevention (backoff on rapid failures)
37
- * - Comprehensive lifecycle logging
38
- */
39
- function setupClusterPrimary(opts) {
40
- const numWorkers = opts.workers ?? os.cpus().length;
41
- const gracefulTimeout = opts.gracefulShutdownTimeout ?? 5e3;
42
- const restartDelay = opts.restartDelay ?? 1e3;
43
- const maxFailures = opts.maxFailures ?? 5;
44
- const restartWindow = opts.restartWindow ?? 3e4;
45
- const startupTimeouts = /* @__PURE__ */ new Map();
46
- const state = reactive({
47
- failureTimestamps: [],
48
- shuttingDown: false
49
- });
50
- const activeWorkers = ref(0);
51
- log$1.info(`Primary ${process.pid} starting ${numWorkers} worker(s)`);
52
- for (let i = 0; i < numWorkers; i++) cluster.fork();
53
- cluster.on("fork", (worker) => {
54
- const timeout = setTimeout(() => {
55
- log$1.error(`Worker ${worker.process.pid} did not respond within 10s, killing...`);
56
- worker.kill();
57
- }, 1e4);
58
- startupTimeouts.set(worker.id, timeout);
59
- activeWorkers.value++;
60
- log$1.debug(`Worker ${worker.process.pid} forked (id=${worker.id})`);
61
- });
62
- cluster.on("listening", (worker, address) => {
63
- const timeout = startupTimeouts.get(worker.id);
64
- if (timeout) {
65
- clearTimeout(timeout);
66
- startupTimeouts.delete(worker.id);
67
- }
68
- log$1.info(`Worker ${worker.process.pid} listening on ${address.address}:${address.port}`);
69
- });
70
- cluster.on("online", (worker) => {
71
- log$1.debug(`Worker ${worker.process.pid} online (id=${worker.id})`);
72
- });
73
- cluster.on("exit", (worker, code, signal) => {
74
- const timeout = startupTimeouts.get(worker.id);
75
- if (timeout) {
76
- clearTimeout(timeout);
77
- startupTimeouts.delete(worker.id);
78
- }
79
- activeWorkers.value--;
80
- if (worker.exitedAfterDisconnect) {
81
- log$1.info(`Worker ${worker.process.pid} exited gracefully (id=${worker.id})`);
82
- return;
83
- }
84
- const now = Date.now();
85
- while (state.failureTimestamps.length > 0 && now - state.failureTimestamps[0] >= restartWindow) state.failureTimestamps.shift();
86
- state.failureTimestamps.push(now);
87
- if (state.failureTimestamps.length > maxFailures) {
88
- log$1.error(`${state.failureTimestamps.length} worker failures in ${restartWindow}ms, giving up`);
89
- if (activeWorkers.value === 0) {
90
- log$1.error("All workers have crashed, exiting primary");
91
- process.exit(1);
92
- }
93
- return;
94
- }
95
- log$1.warn(`Worker ${worker.process.pid} died (code=${code}, signal=${signal}), restarting in ${restartDelay}ms... (failures: ${state.failureTimestamps.length}/${maxFailures})`);
96
- setTimeout(() => {
97
- if (activeWorkers.value < numWorkers) cluster.fork();
98
- }, restartDelay);
99
- });
100
- cluster.on("disconnect", (worker) => {
101
- log$1.debug(`Worker ${worker.process.pid} disconnected (id=${worker.id})`);
102
- });
103
- for (const signal of ["SIGTERM", "SIGINT"]) process.on(signal, () => {
104
- if (state.shuttingDown) return;
105
- state.shuttingDown = true;
106
- log$1.info(`Primary received ${signal}, disconnecting workers...`);
107
- cluster.disconnect(() => {
108
- log$1.info("All workers disconnected, exiting primary");
109
- process.exit(0);
110
- });
111
- setTimeout(() => {
112
- log$1.warn("Graceful shutdown timed out, forcing exit");
113
- process.exit(1);
114
- }, gracefulTimeout).unref();
115
- });
116
- }
117
- //#endregion
118
- //#region src/http/bootstrap.ts
119
- /** Reload env from .env file (HMR rebuild) — config now lives in-tree. */
120
- function tryReloadEnv() {
121
- try {
122
- reloadEnv();
123
- } catch {}
124
- }
125
- const log = createLogger("Process");
126
- /**
127
- * Bootstrap a KickJS application.
128
- *
129
- * Creates the Express app, registers modules and adapters, and starts
130
- * the HTTP server. In dev mode (`kick dev`), the Vite plugin manages
131
- * the server and HMR — source changes are picked up instantly without
132
- * losing database connections or WebSocket state.
133
- *
134
- * @returns The {@link Application} instance.
135
- *
136
- * @example
137
- * ```ts
138
- * // src/index.ts
139
- * import 'reflect-metadata'
140
- * import { bootstrap } from '@forinda/kickjs'
141
- * import { modules } from './modules'
142
- *
143
- * export const app = await bootstrap({ modules })
144
- * ```
145
- */
146
- async function bootstrap(options) {
147
- const isViteDev = !!globalThis.__kickjs_httpServer;
148
- if (options.cluster && isViteDev) log.warn("Cluster mode is ignored in dev — Vite owns the server. Cluster applies in production (kick start).");
149
- if (options.cluster && cluster.isPrimary && !isViteDev) {
150
- setupClusterPrimary(typeof options.cluster === "object" ? options.cluster : {});
151
- return new Application(options);
152
- }
153
- const g = globalThis;
154
- const processHooks = options.processHooks ?? "auto";
155
- if (!g.__kickBootstrapped) {
156
- if (processHooks !== "manual") {
157
- process.on("uncaughtException", (err) => {
158
- log.error(err, "Uncaught exception");
159
- });
160
- process.on("unhandledRejection", (reason) => {
161
- log.error(reason, "Unhandled rejection");
162
- });
163
- }
164
- if (processHooks === "auto" && !g.__kickjs_httpServer) for (const signal of ["SIGINT", "SIGTERM"]) process.on(signal, async () => {
165
- log.info(`Received ${signal}, shutting down...`);
166
- if (g.__app) await g.__app.shutdown();
167
- process.exit(0);
168
- });
169
- g.__kickBootstrapped = true;
170
- }
171
- if (g.__app) {
172
- log.debug("HMR rebuild triggered");
173
- tryReloadEnv();
174
- Container.reset();
175
- const freshApp = new Application(options);
176
- g.__app = freshApp;
177
- g.__kickjs_container = freshApp.getContainer();
178
- await freshApp.start();
179
- log.debug("HMR rebuild complete");
180
- return freshApp;
181
- }
182
- const app = new Application(options);
183
- g.__app = app;
184
- g.__kickjs_container = app.getContainer();
185
- if (process.env.KICK_TINKER) {
186
- await app.registerOnly();
187
- return app;
188
- }
189
- await app.start();
190
- return app;
191
- }
192
- //#endregion
193
- export { isClusterPrimary as n, bootstrap as t };
194
-
195
- //# sourceMappingURL=bootstrap-kPcmbbWe.mjs.map
@@ -1,135 +0,0 @@
1
- /**
2
- * @forinda/kickjs v5.3.0
3
- *
4
- * Copyright (c) Felix Orinda
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- import { Service } from "./core/decorators.mjs";
12
- import { a as reloadEnv, i as loadEnv } from "./env-C4Yr6nN8.mjs";
13
- //#region \0@oxc-project+runtime@0.122.0/helpers/decorate.js
14
- function __decorate(decorators, target, key, desc) {
15
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
17
- 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;
18
- return c > 3 && r && Object.defineProperty(target, key, r), r;
19
- }
20
- //#endregion
21
- //#region src/config/config-service.ts
22
- let ConfigService = class ConfigService {
23
- /**
24
- * Read the current parsed env on every access. We deliberately do **not**
25
- * snapshot in the constructor: if `ConfigService` is instantiated before
26
- * the user's `defineEnv()` schema has been registered (e.g. DI wires it
27
- * eagerly, or HMR's `reloadEnv()` cleared the cache between rebuilds),
28
- * an eager snapshot would freeze the base shape and never see the
29
- * extended values — even though `@Value()` (which reads lazily through
30
- * `Container._envResolver`) would resolve them correctly.
31
- *
32
- * `loadEnv()` is sticky: once an extended schema has been parsed it
33
- * keeps returning that schema's values, so this getter is cheap (one
34
- * cached lookup) and always consistent with `@Value`.
35
- */
36
- get env() {
37
- return loadEnv();
38
- }
39
- /**
40
- * Get an env variable by key.
41
- *
42
- * - When `kick typegen` has run, `key` is constrained to known
43
- * `KickEnv` keys and the return type is inferred from the schema.
44
- * - When `KickEnv` is empty (no typegen run yet), any string is
45
- * accepted and `T` falls back to the explicit generic for
46
- * back-compat.
47
- */
48
- get(key) {
49
- return this.env[key];
50
- }
51
- /**
52
- * Get all env config as a readonly object. When `KickEnv` is
53
- * populated by typegen, returns `Readonly<KickEnv>` so the caller
54
- * gets autocomplete on every key.
55
- */
56
- getAll() {
57
- return Object.freeze({ ...this.env });
58
- }
59
- /** Reload env from .env file (for HMR / file-watch scenarios) */
60
- reload() {
61
- reloadEnv();
62
- loadEnv();
63
- }
64
- isProduction() {
65
- return this.env.NODE_ENV === "production";
66
- }
67
- isDevelopment() {
68
- return this.env.NODE_ENV === "development";
69
- }
70
- isTest() {
71
- return this.env.NODE_ENV === "test";
72
- }
73
- };
74
- ConfigService = __decorate([Service()], ConfigService);
75
- /**
76
- * Create a typed ConfigService class bound to a specific Zod env schema.
77
- * The returned class is DI-injectable via `@Service()` and provides
78
- * fully typed `get()` with key autocomplete.
79
- *
80
- * @example
81
- * ```ts
82
- * const envSchema = defineEnv((base) =>
83
- * base.extend({
84
- * DATABASE_URL: z.string().url(),
85
- * JWT_SECRET: z.string().min(32),
86
- * })
87
- * )
88
- *
89
- * // Create a typed, injectable config service
90
- * export const AppConfigService = createConfigService(envSchema)
91
- * export type AppConfigService = InstanceType<typeof AppConfigService>
92
- *
93
- * // In a controller or service — inject it:
94
- * @Controller()
95
- * class UserController {
96
- * constructor(@Inject(AppConfigService) private config: AppConfigService) {
97
- * const dbUrl = config.get('DATABASE_URL') // string — autocompletes!
98
- * const bad = config.get('NOPE') // TS error
99
- * }
100
- * }
101
- * ```
102
- */
103
- function createConfigService(schema) {
104
- let SchemaConfigService = class SchemaConfigService {
105
- /** See note on `ConfigService.env` — same eager-snapshot hazard. */
106
- get env() {
107
- return loadEnv(schema);
108
- }
109
- get(key) {
110
- return this.env[key];
111
- }
112
- getAll() {
113
- return Object.freeze({ ...this.env });
114
- }
115
- reload() {
116
- reloadEnv();
117
- loadEnv(schema);
118
- }
119
- isProduction() {
120
- return this.env.NODE_ENV === "production";
121
- }
122
- isDevelopment() {
123
- return this.env.NODE_ENV === "development";
124
- }
125
- isTest() {
126
- return this.env.NODE_ENV === "test";
127
- }
128
- };
129
- SchemaConfigService = __decorate([Service()], SchemaConfigService);
130
- return SchemaConfigService;
131
- }
132
- //#endregion
133
- export { createConfigService as n, ConfigService as t };
134
-
135
- //# sourceMappingURL=config-DxEREQmR.mjs.map