@forinda/kickjs 2.1.0 → 2.2.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/README.md +63 -20
  2. package/dist/{adapter-BqGjZCSm.d.mts → adapter-wuoBNkNs.d.mts} +3 -3
  3. package/dist/{adapter-BqGjZCSm.d.mts.map → adapter-wuoBNkNs.d.mts.map} +1 -1
  4. package/dist/{app-module-CcEbAVtB.d.mts → app-module-DOBmxARW.d.mts} +11 -4
  5. package/dist/app-module-DOBmxARW.d.mts.map +1 -0
  6. package/dist/{application-DNHj-_UL.mjs → application-C5Q720a2.mjs} +6 -6
  7. package/dist/application-C5Q720a2.mjs.map +1 -0
  8. package/dist/{bootstrap-DLEZaJ3b.mjs → bootstrap-dEN6SjBl.mjs} +6 -6
  9. package/dist/{bootstrap-DLEZaJ3b.mjs.map → bootstrap-dEN6SjBl.mjs.map} +1 -1
  10. package/dist/{cache-DJeMaGqb.d.mts → cache-PufEhr0n.d.mts} +1 -1
  11. package/dist/{cache-DJeMaGqb.d.mts.map → cache-PufEhr0n.d.mts.map} +1 -1
  12. package/dist/{chunk-C5Qp-JxE.mjs → chunk-C9tIbwLT.mjs} +1 -1
  13. package/dist/container-B7jFEbPE.mjs +496 -0
  14. package/dist/container-B7jFEbPE.mjs.map +1 -0
  15. package/dist/{container-nBSIhyqV.d.mts → container-CcgV8eHL.d.mts} +116 -4
  16. package/dist/container-CcgV8eHL.d.mts.map +1 -0
  17. package/dist/core/adapter.d.mts +1 -1
  18. package/dist/core/adapter.mjs +1 -1
  19. package/dist/core/app-module.d.mts +1 -1
  20. package/dist/core/app-module.mjs +1 -1
  21. package/dist/core/cache.d.mts +1 -1
  22. package/dist/core/cache.mjs +1 -1
  23. package/dist/core/container.d.mts +2 -2
  24. package/dist/core/container.mjs +2 -416
  25. package/dist/core/cron.d.mts +1 -1
  26. package/dist/core/cron.mjs +2 -2
  27. package/dist/core/decorators.d.mts +2 -2
  28. package/dist/core/decorators.mjs +9 -3
  29. package/dist/core/decorators.mjs.map +1 -1
  30. package/dist/core/errors.d.mts +1 -1
  31. package/dist/core/errors.mjs +1 -1
  32. package/dist/core/interfaces.d.mts +1 -1
  33. package/dist/core/interfaces.mjs +1 -1
  34. package/dist/core/logger.d.mts +1 -1
  35. package/dist/core/logger.mjs +1 -1
  36. package/dist/core/path.d.mts +1 -1
  37. package/dist/core/path.mjs +1 -1
  38. package/dist/core/plugin.d.mts +1 -1
  39. package/dist/core/plugin.mjs +1 -1
  40. package/dist/core/reactivity.d.mts +1 -1
  41. package/dist/core/reactivity.mjs +1 -1
  42. package/dist/{core-BL_H8fEZ.mjs → core-CMgIoRvg.mjs} +4 -4
  43. package/dist/{core-BL_H8fEZ.mjs.map → core-CMgIoRvg.mjs.map} +1 -1
  44. package/dist/{cron-RKhH5TOd.d.mts → cron-C29iHvHT.d.mts} +1 -1
  45. package/dist/{cron-RKhH5TOd.d.mts.map → cron-C29iHvHT.d.mts.map} +1 -1
  46. package/dist/{decorators-CQ93ak6Z.d.mts → decorators-D3lBlmud.d.mts} +54 -4
  47. package/dist/decorators-D3lBlmud.d.mts.map +1 -0
  48. package/dist/{errors-te5Km00o.d.mts → errors-BZUdxtjC.d.mts} +1 -1
  49. package/dist/{errors-te5Km00o.d.mts.map → errors-BZUdxtjC.d.mts.map} +1 -1
  50. package/dist/http/application.d.mts +4 -4
  51. package/dist/http/application.d.mts.map +1 -1
  52. package/dist/http/application.mjs +2 -2
  53. package/dist/http/bootstrap.mjs +2 -2
  54. package/dist/http/context.d.mts +67 -8
  55. package/dist/http/context.d.mts.map +1 -1
  56. package/dist/http/context.mjs +10 -5
  57. package/dist/http/context.mjs.map +1 -1
  58. package/dist/http/middleware/cors.mjs +1 -1
  59. package/dist/http/middleware/csrf.mjs +1 -1
  60. package/dist/http/middleware/error-handler.mjs +2 -2
  61. package/dist/http/middleware/helmet.mjs +1 -1
  62. package/dist/http/middleware/rate-limit.mjs +1 -1
  63. package/dist/http/middleware/request-id.mjs +1 -1
  64. package/dist/http/middleware/request-logger.mjs +2 -2
  65. package/dist/http/middleware/session.mjs +1 -1
  66. package/dist/http/middleware/spa.d.mts +1 -1
  67. package/dist/http/middleware/spa.mjs +3 -3
  68. package/dist/http/middleware/upload.d.mts +1 -1
  69. package/dist/http/middleware/upload.mjs +1 -1
  70. package/dist/http/middleware/validate.mjs +1 -1
  71. package/dist/http/middleware/views.d.mts +1 -1
  72. package/dist/http/middleware/views.mjs +2 -2
  73. package/dist/http/query/index.d.mts +2 -2
  74. package/dist/http/query/index.mjs +2 -2
  75. package/dist/http/router-builder.mjs +4 -4
  76. package/dist/{index-C0gbnpSg.d.mts → index-4VM4dUJf.d.mts} +1 -1
  77. package/dist/{index-C0gbnpSg.d.mts.map → index-4VM4dUJf.d.mts.map} +1 -1
  78. package/dist/{index-Cls52etj.d.mts → index-rnK23QBD.d.mts} +39 -3
  79. package/dist/index-rnK23QBD.d.mts.map +1 -0
  80. package/dist/index.d.mts +16 -16
  81. package/dist/index.mjs +8 -8
  82. package/dist/{interfaces-D-48zotH.d.mts → interfaces-D5ohYl6D.d.mts} +1 -1
  83. package/dist/{interfaces-D-48zotH.d.mts.map → interfaces-D5ohYl6D.d.mts.map} +1 -1
  84. package/dist/{logger-Dzj-TF0t.d.mts → logger-BLdfUF5b.d.mts} +1 -1
  85. package/dist/{logger-Dzj-TF0t.d.mts.map → logger-BLdfUF5b.d.mts.map} +1 -1
  86. package/dist/{metadata-fmvikBA0.mjs → metadata-BqXgNTOf.mjs} +2 -2
  87. package/dist/{metadata-fmvikBA0.mjs.map → metadata-BqXgNTOf.mjs.map} +1 -1
  88. package/dist/{path-LmwfhfyH.d.mts → path-Dq5V-i-x.d.mts} +1 -1
  89. package/dist/path-Dq5V-i-x.d.mts.map +1 -0
  90. package/dist/{plugin-DIoPIpSm.d.mts → plugin-D20muJwC.d.mts} +4 -4
  91. package/dist/{plugin-DIoPIpSm.d.mts.map → plugin-D20muJwC.d.mts.map} +1 -1
  92. package/dist/{query-7cdHF6ry.mjs → query-vljPDFaZ.mjs} +6 -6
  93. package/dist/query-vljPDFaZ.mjs.map +1 -0
  94. package/dist/{reactivity-BbS-99ow.d.mts → reactivity-CMAQh0gi.d.mts} +1 -1
  95. package/dist/{reactivity-BbS-99ow.d.mts.map → reactivity-CMAQh0gi.d.mts.map} +1 -1
  96. package/package.json +1 -1
  97. package/dist/app-module-CcEbAVtB.d.mts.map +0 -1
  98. package/dist/application-DNHj-_UL.mjs.map +0 -1
  99. package/dist/container-nBSIhyqV.d.mts.map +0 -1
  100. package/dist/core/container.mjs.map +0 -1
  101. package/dist/decorators-CQ93ak6Z.d.mts.map +0 -1
  102. package/dist/index-Cls52etj.d.mts.map +0 -1
  103. package/dist/path-LmwfhfyH.d.mts.map +0 -1
  104. package/dist/query-7cdHF6ry.mjs.map +0 -1
@@ -1,5 +1,84 @@
1
1
 
2
- import { c as Scope, i as Constructor, r as ClassKind, s as PostConstructStatus } from "./interfaces-D-48zotH.mjs";
2
+ import { c as Scope, i as Constructor, r as ClassKind, s as PostConstructStatus } from "./interfaces-D5ohYl6D.mjs";
3
+ //#region src/core/token.d.ts
4
+ /**
5
+ * Collision-safe injection tokens with phantom type parameters.
6
+ *
7
+ * `createToken<T>(name)` is the recommended way to declare any DI token
8
+ * that isn't a class. Each call returns a unique frozen object — even if
9
+ * two files write `createToken<X>('Logger')`, they produce two distinct
10
+ * references that the container treats as different tokens. Collisions
11
+ * become impossible by construction, not by convention.
12
+ *
13
+ * The phantom type parameter `T` lets `container.resolve(token)` infer
14
+ * the correct return type without any codegen.
15
+ *
16
+ * ## Hardening layers
17
+ *
18
+ * KickJS has four DI token kinds, listed from safest to riskiest:
19
+ *
20
+ * 1. **Class identity** — `container.resolve(UserService)`. Reference
21
+ * equality, never collides. Type-safe via `Constructor<T>` overload.
22
+ * 2. **`createToken<T>(name)`** — frozen object identity, never collides.
23
+ * Type-safe via the `InjectionToken<T>` overload.
24
+ * 3. **Symbol** — `Symbol('foo')` is unique per call but `Symbol.for('foo')`
25
+ * is interned and CAN collide. Discouraged.
26
+ * 4. **Raw string `@Inject('foo')`** — high collision risk, untyped.
27
+ * Reserved for legacy code and runtime-computed token names.
28
+ *
29
+ * Prefer (1) and (2). Use (4) only when you have to.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * // src/tokens.ts
34
+ * export const DATABASE_URL = createToken<string>('config.database.url')
35
+ * export const FEATURE_FLAGS = createToken<FeatureFlags>('app.features')
36
+ *
37
+ * // bootstrap
38
+ * container.registerInstance(DATABASE_URL, process.env.DATABASE_URL!)
39
+ *
40
+ * // anywhere else
41
+ * const url = container.resolve(DATABASE_URL) // typed as `string`
42
+ * ```
43
+ *
44
+ * @module @forinda/kickjs/core/token
45
+ */
46
+ /**
47
+ * Symbol marker stamped on every InjectionToken so the container can
48
+ * detect them at runtime regardless of which package created them.
49
+ *
50
+ * Uses `Symbol.for()` so cross-package isolation (different copies of
51
+ * `@forinda/kickjs` loaded under different module identities) still
52
+ * shares the same marker.
53
+ */
54
+ declare const INJECTION_TOKEN: unique symbol;
55
+ /**
56
+ * A type-safe DI token. Each `createToken()` call returns a unique frozen
57
+ * object identified by reference, not by the `name` string. Two
58
+ * `createToken<X>('foo')` calls in different files produce two distinct
59
+ * tokens that the container treats independently.
60
+ *
61
+ * The phantom `_type` parameter is never assigned at runtime — it exists
62
+ * solely to thread the type through `container.resolve(token)`.
63
+ */
64
+ interface InjectionToken<T> {
65
+ readonly [INJECTION_TOKEN]: true;
66
+ /** Descriptive name used in error messages, logs, and devtools */
67
+ readonly name: string;
68
+ /** Phantom — never assigned at runtime */
69
+ readonly _type?: T;
70
+ }
71
+ /**
72
+ * Create a collision-safe injection token.
73
+ *
74
+ * The returned token is a frozen object identified by reference, not by
75
+ * the `name` string. The `name` is used only for error messages, logs,
76
+ * and debugging.
77
+ */
78
+ declare function createToken<T>(name: string): InjectionToken<T>;
79
+ /** Type guard — returns `true` if `value` is an InjectionToken */
80
+ declare function isInjectionToken(value: unknown): value is InjectionToken<unknown>;
81
+ //#endregion
3
82
  //#region src/core/container.d.ts
4
83
  /** Format a token for display in error messages */
5
84
  declare function tokenName(token: any): string;
@@ -12,6 +91,24 @@ interface ContainerChangeEvent {
12
91
  }
13
92
  /** Listener that receives batched change events */
14
93
  type ContainerChangeListener = (changes: ContainerChangeEvent[]) => void;
94
+ /**
95
+ * Type-safe registry of string DI tokens. Augmented by `kick typegen` —
96
+ * the generated `.kickjs/types/registry.d.ts` adds entries like:
97
+ *
98
+ * ```ts
99
+ * declare module '@forinda/kickjs' {
100
+ * interface KickJsRegistry {
101
+ * UserService: import('../../src/modules/users/user.service').UserService
102
+ * }
103
+ * }
104
+ * ```
105
+ *
106
+ * Once typegen has run, `container.resolve('UserService')` returns the
107
+ * correct type instead of `any`. Class-token resolution
108
+ * (`container.resolve(UserService)`) is already type-safe via the
109
+ * `Constructor<T>` overload and does not need typegen.
110
+ */
111
+ interface KickJsRegistry {}
15
112
  /**
16
113
  * Inversion-of-Control (IoC) container that manages dependency registration,
17
114
  * resolution, and lifecycle. Implements the Singleton pattern so all parts of
@@ -89,7 +186,22 @@ declare class Container {
89
186
  postConstructStatus: PostConstructStatus;
90
187
  dependencies: string[];
91
188
  }>;
92
- /** Resolve a dependency by its token */
189
+ /**
190
+ * Resolve a dependency by its token.
191
+ *
192
+ * Four overloads, in order of preference:
193
+ * - **`InjectionToken<T>`** (from `createToken<T>(name)`) → returns `T`.
194
+ * Collision-safe by construction; no codegen required.
195
+ * - **Class constructor** → returns an instance of that class. Always
196
+ * type-safe; no codegen required.
197
+ * - **String token in `KickJsRegistry`** (populated by `kick typegen`) →
198
+ * returns the augmented type.
199
+ * - **Anything else** → returns `any`. Use this only for legacy code or
200
+ * string tokens that haven't been registered with typegen yet.
201
+ */
202
+ resolve<T>(token: InjectionToken<T>): T;
203
+ resolve<T>(token: Constructor<T>): T;
204
+ resolve<K extends keyof KickJsRegistry & string>(token: K): KickJsRegistry[K];
93
205
  resolve<T = any>(token: any): T;
94
206
  /** Lifecycle hook called during Application.setup() after module registration */
95
207
  bootstrap(): void;
@@ -137,5 +249,5 @@ declare class Container {
137
249
  private injectProperties;
138
250
  }
139
251
  //#endregion
140
- export { tokenName as i, ContainerChangeEvent as n, ContainerChangeListener as r, Container as t };
141
- //# sourceMappingURL=container-nBSIhyqV.d.mts.map
252
+ export { tokenName as a, createToken as c, KickJsRegistry as i, isInjectionToken as l, ContainerChangeEvent as n, INJECTION_TOKEN as o, ContainerChangeListener as r, InjectionToken as s, Container as t };
253
+ //# sourceMappingURL=container-CcgV8eHL.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"container-CcgV8eHL.d.mts","names":[],"sources":["../src/core/token.ts","../src/core/container.ts"],"mappings":";;;;;;;AAmDA;;;;;AAWA;;;;;;;;;;;AAeA;;;;;;;;;;AAQA;;;;;;;;;;;;ACnCA;;;;;AAqBA;;;AArBA,cDCa,eAAA;;;;;;;;AC4Bb;;UDjBiB,cAAA;EAAA,UACL,eAAA;ECgB0D;EAAA,SDd3D,IAAA;ECiCoB;EAAA,SD/BpB,KAAA,GAAQ,CAAA;AAAA;;AC8DnB;;;;;;iBDpDgB,WAAA,GAAA,CAAe,IAAA,WAAe,cAAA,CAAe,CAAA;;iBAQ7C,gBAAA,CAAiB,KAAA,YAAiB,KAAA,IAAS,cAAA;;;;iBCnC3C,SAAA,CAAU,KAAA;;UAqBT,oBAAA;EACf,KAAA;EACA,KAAA;EACA,IAAA,GAAO,SAAA;EACP,SAAA;AAAA;;KAIU,uBAAA,IAA2B,OAAA,EAAS,oBAAA;;;;;;;ADFhD;;;;;;;;;;AAQA;UCaiB,cAAA;;;;;;;;;;AAhDjB;;cA+Ea,SAAA;EAAA,eACI,QAAA;EAAA,QACP,aAAA;EAAA,QACA,SAAA;EAAA,QAGA,eAAA;EAAA,QACA,cAAA;EAAA,QACA,WAAA;EAAA,wBACgB,WAAA;EAjExB;EAAA,OAoEO,QAAA,IAAY,SAAA,EAAW,SAAA;EAnEvB;EAAA,OAqEA,QAAA,IAAY,SAAA,EAAW,SAAA;EApErB;;AAIX;;EAJW,OAyEF,YAAA,IAAgB,GAAA;EArEuB;;AAmBhD;;;EAnBgD,OA2EvC,qBAAA;IACM,SAAA,EAAW,GAAA;IAAe,MAAA,EAAQ,GAAA;EAAA;EAAA,OAGxC,WAAA,CAAA,GAAe,SAAA;EAjBQ;;;;;EAAA,OAkCvB,KAAA,CAAA;EA0DsB;;;;;;;;;;;EAAA,OALtB,MAAA,CAAA,GAAU,SAAA;EA2IO;EAtIxB,QAAA,CAAS,KAAA,OAAY,MAAA,EAAQ,WAAA,EAAa,KAAA,GAAO,KAAA;EAsIW;EAxH5D,eAAA,CAAgB,KAAA,OAAY,OAAA,aAAoB,KAAA,GAAO,KAAA;EAyHzB;EAlF9B,gBAAA,CAAiB,KAAA,OAAY,QAAA;EA+Ma;EAlL1C,GAAA,CAAI,KAAA;EAzLW;EA8Lf,gBAAA,CAAA,GAAoB,KAAA;IAClB,KAAA;IACA,KAAA;IACA,IAAA,EAAM,SAAA;IACN,YAAA;IACA,YAAA;IACA,cAAA;IACA,eAAA;IACA,iBAAA;IACA,mBAAA,EAAqB,mBAAA;IACrB,YAAA;EAAA;EAtLK;;;;;;;;;;;;;EAyNP,OAAA,GAAA,CAAW,KAAA,EAAO,cAAA,CAAe,CAAA,IAAK,CAAA;EACtC,OAAA,GAAA,CAAW,KAAA,EAAO,WAAA,CAAY,CAAA,IAAK,CAAA;EACnC,OAAA,iBAAwB,cAAA,UAAA,CAAyB,KAAA,EAAO,CAAA,GAAI,cAAA,CAAe,CAAA;EAC3E,OAAA,SAAA,CAAiB,KAAA,QAAa,CAAA;EAvIY;EAqO1C,SAAA,CAAA;EAvNgB;;;;;;;;;;;;;;;;;;;;;;;;EAsPhB,QAAA,CAAS,QAAA,EAAU,uBAAA;EAhID;;;;;;;;EA6IlB,UAAA,CAAW,KAAA;EA5IwB;EAAA,QAqK3B,IAAA;EApKA;EAsLR,YAAA,CAAA;EAAA,QAgBQ,cAAA;EAtMyC;EAAA,QAoQzC,mBAAA;EAAA,QASA,gBAAA;AAAA"}
@@ -1,3 +1,3 @@
1
1
 
2
- import { a as MiddlewarePhase, i as AppAdapterClass, n as AdapterMiddleware, r as AppAdapter, t as AdapterContext } from "../adapter-BqGjZCSm.mjs";
2
+ import { a as MiddlewarePhase, i as AppAdapterClass, n as AdapterMiddleware, r as AppAdapter, t as AdapterContext } from "../adapter-wuoBNkNs.mjs";
3
3
  export { AdapterContext, AdapterMiddleware, AppAdapter, AppAdapterClass, MiddlewarePhase };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @forinda/kickjs v2.1.0
2
+ * @forinda/kickjs v2.2.0
3
3
  *
4
4
  * Copyright (c) Felix Orinda
5
5
  *
@@ -1,3 +1,3 @@
1
1
 
2
- import { n as AppModuleClass, r as ModuleRoutes, t as AppModule } from "../app-module-CcEbAVtB.mjs";
2
+ import { n as AppModuleClass, r as ModuleRoutes, t as AppModule } from "../app-module-DOBmxARW.mjs";
3
3
  export { AppModule, AppModuleClass, ModuleRoutes };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @forinda/kickjs v2.1.0
2
+ * @forinda/kickjs v2.2.0
3
3
  *
4
4
  * Copyright (c) Felix Orinda
5
5
  *
@@ -1,3 +1,3 @@
1
1
 
2
- import { a as Cacheable, c as setCacheProvider, i as CacheProvider, n as CacheEvict, o as MemoryCacheProvider, r as CacheOptions, s as getCacheProvider, t as CACHEABLE_META } from "../cache-DJeMaGqb.mjs";
2
+ import { a as Cacheable, c as setCacheProvider, i as CacheProvider, n as CacheEvict, o as MemoryCacheProvider, r as CacheOptions, s as getCacheProvider, t as CACHEABLE_META } from "../cache-PufEhr0n.mjs";
3
3
  export { CACHEABLE_META, CacheEvict, CacheOptions, CacheProvider, Cacheable, MemoryCacheProvider, getCacheProvider, setCacheProvider };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @forinda/kickjs v2.1.0
2
+ * @forinda/kickjs v2.2.0
3
3
  *
4
4
  * Copyright (c) Felix Orinda
5
5
  *
@@ -1,3 +1,3 @@
1
1
 
2
- import { i as tokenName, n as ContainerChangeEvent, r as ContainerChangeListener, t as Container } from "../container-nBSIhyqV.mjs";
3
- export { Container, ContainerChangeEvent, ContainerChangeListener, tokenName };
2
+ import { a as tokenName, i as KickJsRegistry, n as ContainerChangeEvent, r as ContainerChangeListener, t as Container } from "../container-CcgV8eHL.mjs";
3
+ export { Container, ContainerChangeEvent, ContainerChangeListener, KickJsRegistry, tokenName };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @forinda/kickjs v2.1.0
2
+ * @forinda/kickjs v2.2.0
3
3
  *
4
4
  * Copyright (c) Felix Orinda
5
5
  *
@@ -8,419 +8,5 @@
8
8
  *
9
9
  * @license MIT
10
10
  */
11
- import { METADATA, Scope } from "./interfaces.mjs";
12
- import { createLogger } from "./logger.mjs";
13
- import { i as getMetaRecord, n as getClassMetaOrUndefined, o as getMethodMetaOrUndefined, r as getMetaMap, t as getClassMeta } from "../metadata-fmvikBA0.mjs";
14
- import "reflect-metadata";
15
- //#region src/core/container.ts
16
- const log = createLogger("Container");
17
- /** Create a Registration with observability defaults */
18
- function createReg(fields) {
19
- return {
20
- kind: "unknown",
21
- resolveCount: 0,
22
- postConstructStatus: "skipped",
23
- dependencies: [],
24
- ...fields
25
- };
26
- }
27
- /** Format a token for display in error messages */
28
- function tokenName(token) {
29
- if (typeof token === "symbol") return token.toString();
30
- return token?.name || String(token);
31
- }
32
- function getPersistentStore() {
33
- if (!globalThis.__kickjs_persistent) globalThis.__kickjs_persistent = {
34
- factories: [],
35
- instances: [],
36
- resolvedInstances: /* @__PURE__ */ new Map()
37
- };
38
- return globalThis.__kickjs_persistent;
39
- }
40
- /**
41
- * Inversion-of-Control (IoC) container that manages dependency registration,
42
- * resolution, and lifecycle. Implements the Singleton pattern so all parts of
43
- * the application share a single container instance.
44
- *
45
- * Supports constructor injection, property injection (@Autowired),
46
- * factory registrations, and lifecycle hooks (@PostConstruct).
47
- *
48
- * Persistent state (DB connections, Redis, etc.) is stored on globalThis so
49
- * it survives both Container.reset() and Vite module re-evaluation.
50
- */
51
- var Container = class Container {
52
- static instance;
53
- registrations = /* @__PURE__ */ new Map();
54
- resolving = /* @__PURE__ */ new Set();
55
- changeListeners = /* @__PURE__ */ new Set();
56
- pendingChanges = [];
57
- notifyTimer = null;
58
- static DEBOUNCE_MS = 50;
59
- /** Callback set by the decorators module to flush pending registrations */
60
- static _onReady = null;
61
- /** Callback invoked on reset so decorators can update their container reference */
62
- static _onReset = null;
63
- /**
64
- * Environment resolver for @Value decorator. Set by @forinda/kickjs-config
65
- * to return Zod-validated, type-coerced env values instead of raw process.env strings.
66
- */
67
- static _envResolver = null;
68
- /**
69
- * Request store provider for REQUEST-scoped DI. Set by @forinda/kickjs-http
70
- * to return the current request's AsyncLocalStorage store.
71
- * Returns { instances: Map, values: Map } or null if outside a request.
72
- */
73
- static _requestStoreProvider = null;
74
- static getInstance() {
75
- if (!Container.instance) Container.instance = new Container();
76
- if (Container._onReady) {
77
- Container._onReady(Container.instance);
78
- Container._onReady = null;
79
- }
80
- return Container.instance;
81
- }
82
- /**
83
- * Resets the container by replacing the singleton with a fresh instance.
84
- * Persistent registrations (DB, Redis, etc.) are replayed from globalThis
85
- * so they survive both reset() and Vite module re-evaluation.
86
- */
87
- static reset() {
88
- Container.instance = new Container();
89
- Container._onReset?.(Container.instance);
90
- const store = getPersistentStore();
91
- for (const { token, factory, scope } of store.factories) if (!Container.instance.has(token)) {
92
- const name = tokenName(token);
93
- const existing = store.resolvedInstances.get(name);
94
- Container.instance.registrations.set(token, createReg({
95
- target: Object,
96
- scope,
97
- factory,
98
- kind: "factory",
99
- instance: existing,
100
- resolveCount: existing ? 1 : 0,
101
- postConstructStatus: existing ? "completed" : "skipped"
102
- }));
103
- }
104
- for (const { token, instance } of store.instances) if (!Container.instance.has(token)) Container.instance.registrations.set(token, createReg({
105
- target: instance.constructor,
106
- scope: Scope.SINGLETON,
107
- instance,
108
- kind: "instance",
109
- postConstructStatus: "completed",
110
- resolveCount: 1
111
- }));
112
- }
113
- /**
114
- * Create an isolated container instance (not the global singleton).
115
- * Useful for concurrent tests that must not share DI state.
116
- *
117
- * @example
118
- * ```ts
119
- * const container = Container.create()
120
- * container.register(UserService, UserService)
121
- * const svc = container.resolve(UserService)
122
- * ```
123
- */
124
- static create() {
125
- return new Container();
126
- }
127
- /** Register a class constructor under the given token */
128
- register(token, target, scope = Scope.SINGLETON) {
129
- const kind = getClassMeta(METADATA.CLASS_KIND, target, "unknown");
130
- const reg = createReg({
131
- target,
132
- scope,
133
- kind,
134
- dependencies: this.extractDependencies(target)
135
- });
136
- this.registrations.set(token, reg);
137
- if (typeof token === "function" && token.name) this.registrations.set(`__hmr__${token.name}`, reg);
138
- this.emit(tokenName(token), "registered", kind);
139
- }
140
- /** Register a factory function under the given token */
141
- registerFactory(token, factory, scope = Scope.SINGLETON) {
142
- const store = getPersistentStore();
143
- const name = tokenName(token);
144
- const factoryUnchanged = store.factories.find((r) => tokenName(r.token) === name)?.factory === factory;
145
- const existingInstance = factoryUnchanged ? store.resolvedInstances.get(name) : void 0;
146
- if (!factoryUnchanged) store.resolvedInstances.delete(name);
147
- this.registrations.set(token, createReg({
148
- target: Object,
149
- scope,
150
- factory,
151
- kind: "factory",
152
- instance: existingInstance,
153
- resolveCount: existingInstance ? 1 : 0,
154
- postConstructStatus: existingInstance ? "completed" : "skipped"
155
- }));
156
- const idx = store.factories.findIndex((r) => tokenName(r.token) === name);
157
- if (idx >= 0) store.factories[idx] = {
158
- token,
159
- factory,
160
- scope
161
- };
162
- else store.factories.push({
163
- token,
164
- factory,
165
- scope
166
- });
167
- this.emit(name, "registered", "factory");
168
- }
169
- /** Register a pre-constructed singleton instance */
170
- registerInstance(token, instance) {
171
- const store = getPersistentStore();
172
- const name = tokenName(token);
173
- this.registrations.set(token, createReg({
174
- target: instance.constructor,
175
- scope: Scope.SINGLETON,
176
- instance,
177
- kind: "instance",
178
- postConstructStatus: "completed",
179
- resolveCount: 1,
180
- firstResolvedAt: Date.now(),
181
- lastResolvedAt: Date.now()
182
- }));
183
- store.resolvedInstances.set(name, instance);
184
- const idx = store.instances.findIndex((r) => tokenName(r.token) === name);
185
- if (idx >= 0) store.instances[idx] = {
186
- token,
187
- instance
188
- };
189
- else store.instances.push({
190
- token,
191
- instance
192
- });
193
- this.emit(name, "registered", "instance");
194
- }
195
- /** Check if a binding exists for the given token */
196
- has(token) {
197
- return this.registrations.has(token);
198
- }
199
- /** Return a snapshot of all registered tokens with their scope and instantiation status */
200
- getRegistrations() {
201
- const entries = [];
202
- for (const [token, reg] of this.registrations) entries.push({
203
- token: tokenName(token),
204
- scope: reg.scope,
205
- kind: reg.kind,
206
- instantiated: reg.scope === Scope.SINGLETON ? reg.instance !== void 0 : reg.resolveCount > 0,
207
- resolveCount: reg.resolveCount,
208
- lastResolvedAt: reg.lastResolvedAt,
209
- firstResolvedAt: reg.firstResolvedAt,
210
- resolveDurationMs: reg.resolveDurationMs,
211
- postConstructStatus: reg.postConstructStatus,
212
- dependencies: reg.dependencies
213
- });
214
- return entries;
215
- }
216
- /** Resolve a dependency by its token */
217
- resolve(token) {
218
- let reg = this.registrations.get(token);
219
- if (!reg && typeof token === "function" && token.name) reg = this.registrations.get(`__hmr__${token.name}`);
220
- if (!reg) throw new Error(`No binding found for: ${tokenName(token)}`);
221
- if (reg.scope === Scope.SINGLETON && reg.instance !== void 0) {
222
- reg.resolveCount++;
223
- reg.lastResolvedAt = Date.now();
224
- return reg.instance;
225
- }
226
- if (reg.scope === Scope.REQUEST) {
227
- if (!Container._requestStoreProvider) throw new Error(`Cannot resolve REQUEST-scoped "${tokenName(token)}": no request store provider configured. Ensure requestScopeMiddleware() is in your middleware pipeline.`);
228
- const store = Container._requestStoreProvider();
229
- if (!store) throw new Error(`Cannot resolve REQUEST-scoped "${tokenName(token)}" outside an HTTP request context.`);
230
- if (store.values.has(token)) {
231
- reg.resolveCount++;
232
- reg.lastResolvedAt = Date.now();
233
- return store.values.get(token);
234
- }
235
- if (store.instances.has(token)) {
236
- reg.resolveCount++;
237
- reg.lastResolvedAt = Date.now();
238
- return store.instances.get(token);
239
- }
240
- const start = performance.now();
241
- const instance = this.createInstance(reg);
242
- reg.resolveDurationMs = performance.now() - start;
243
- reg.resolveCount++;
244
- reg.lastResolvedAt = Date.now();
245
- if (!reg.firstResolvedAt) reg.firstResolvedAt = Date.now();
246
- store.instances.set(token, instance);
247
- return instance;
248
- }
249
- if (reg.factory) {
250
- const start = performance.now();
251
- const instance = reg.factory();
252
- reg.resolveDurationMs = performance.now() - start;
253
- reg.resolveCount++;
254
- reg.lastResolvedAt = Date.now();
255
- if (!reg.firstResolvedAt) reg.firstResolvedAt = Date.now();
256
- if (reg.scope === Scope.SINGLETON) {
257
- reg.instance = instance;
258
- getPersistentStore().resolvedInstances.set(tokenName(token), instance);
259
- }
260
- return instance;
261
- }
262
- if (this.resolving.has(token)) {
263
- const chain = [...this.resolving].map(tokenName);
264
- chain.push(tokenName(token));
265
- throw new Error(`Circular dependency detected: ${chain.join(" -> ")}`);
266
- }
267
- this.resolving.add(token);
268
- try {
269
- const start = performance.now();
270
- const instance = this.createInstance(reg);
271
- reg.resolveDurationMs = performance.now() - start;
272
- reg.resolveCount++;
273
- reg.lastResolvedAt = Date.now();
274
- if (!reg.firstResolvedAt) reg.firstResolvedAt = Date.now();
275
- if (reg.scope === Scope.SINGLETON) reg.instance = instance;
276
- return instance;
277
- } finally {
278
- this.resolving.delete(token);
279
- }
280
- }
281
- /** Lifecycle hook called during Application.setup() after module registration */
282
- bootstrap() {}
283
- /**
284
- * Subscribe to container changes. Returns an unsubscribe function.
285
- *
286
- * Changes are batched (50ms debounce) so bulk operations like
287
- * `kick g module` creating 10+ files emit ONE batch, not 10 events.
288
- *
289
- * Any adapter can subscribe:
290
- * - SwaggerAdapter: re-build spec when controllers change
291
- * - DevToolsAdapter: push SSE events to dashboard
292
- * - WsAdapter: re-discover namespaces when controllers change
293
- * - OtelAdapter: emit tracing spans for DI resolution
294
- * - Custom user adapters
295
- *
296
- * @example
297
- * ```ts
298
- * const unsub = container.onChange((changes) => {
299
- * for (const c of changes) {
300
- * console.log(`${c.event}: ${c.token} (${c.kind})`)
301
- * }
302
- * })
303
- * // later:
304
- * unsub()
305
- * ```
306
- */
307
- onChange(callback) {
308
- this.changeListeners.add(callback);
309
- return () => this.changeListeners.delete(callback);
310
- }
311
- /**
312
- * Invalidate a specific registration. Clears the cached instance so the
313
- * next resolve() creates a fresh one. Also invalidates dependents
314
- * (anything that injected this token) by walking the dependency graph.
315
- *
316
- * Called by the Vite HMR plugin when a module file changes.
317
- * Skips persistent registrations (DB connections, etc.).
318
- */
319
- invalidate(token) {
320
- const name = tokenName(token);
321
- const reg = this.registrations.get(token) ?? this.registrations.get(`__hmr__${name}`);
322
- if (!reg) return;
323
- if (getPersistentStore().resolvedInstances.has(name)) return;
324
- reg.instance = void 0;
325
- reg.resolveCount = 0;
326
- reg.postConstructStatus = "skipped";
327
- this.emit(name, "invalidated", reg.kind);
328
- for (const [depToken, depReg] of this.registrations) if (depReg.dependencies.includes(name)) this.invalidate(depToken);
329
- }
330
- /** Batch-emit a change event (debounced, flushed after 50ms of quiet) */
331
- emit(token, event, kind) {
332
- this.pendingChanges.push({
333
- token,
334
- event,
335
- kind,
336
- timestamp: Date.now()
337
- });
338
- if (this.notifyTimer) clearTimeout(this.notifyTimer);
339
- this.notifyTimer = setTimeout(() => {
340
- const batch = this.pendingChanges.splice(0);
341
- if (batch.length === 0) return;
342
- for (const listener of this.changeListeners) try {
343
- listener(batch);
344
- } catch {}
345
- }, Container.DEBOUNCE_MS);
346
- }
347
- /** Flush pending change events immediately (useful in tests) */
348
- flushChanges() {
349
- if (this.notifyTimer) {
350
- clearTimeout(this.notifyTimer);
351
- this.notifyTimer = null;
352
- }
353
- const batch = this.pendingChanges.splice(0);
354
- if (batch.length === 0) return;
355
- for (const listener of this.changeListeners) try {
356
- listener(batch);
357
- } catch {}
358
- }
359
- createInstance(reg) {
360
- const args = getClassMeta(METADATA.PARAM_TYPES, reg.target, []).map((paramType, index) => {
361
- const token = getMetaRecord(METADATA.INJECT, reg.target)[index] || paramType;
362
- if (reg.scope === Scope.SINGLETON) {
363
- const depReg = this.registrations.get(token);
364
- if (depReg && depReg.scope === Scope.REQUEST) throw new Error(`Cannot inject REQUEST-scoped "${tokenName(token)}" into SINGLETON "${tokenName(reg.target)}". Singletons outlive requests. Use TRANSIENT or REQUEST scope for the parent.`);
365
- }
366
- return this.resolve(token);
367
- });
368
- const instance = new reg.target(...args);
369
- this.injectProperties(instance, reg.target);
370
- const postConstruct = getClassMetaOrUndefined(METADATA.POST_CONSTRUCT, reg.target.prototype);
371
- if (postConstruct && typeof instance[postConstruct] === "function") try {
372
- const result = instance[postConstruct]();
373
- if (result && typeof result.then === "function") {
374
- reg.postConstructStatus = "pending";
375
- result.then(() => {
376
- reg.postConstructStatus = "completed";
377
- }).catch(() => {
378
- reg.postConstructStatus = "failed";
379
- });
380
- log.warn(`@PostConstruct on ${tokenName(reg.target)}.${String(postConstruct)}() returned a Promise but the container is synchronous. The async operation will not be awaited.`);
381
- } else reg.postConstructStatus = "completed";
382
- } catch (err) {
383
- reg.postConstructStatus = "failed";
384
- log.error(err, `@PostConstruct on ${tokenName(reg.target)}.${String(postConstruct)}() threw an error`);
385
- }
386
- return instance;
387
- }
388
- /** Extract dependency token names from constructor metadata */
389
- extractDependencies(target) {
390
- const paramTypes = getClassMeta(METADATA.PARAM_TYPES, target, []);
391
- const injectTokens = getMetaRecord(METADATA.INJECT, target);
392
- return paramTypes.map((type, index) => {
393
- return tokenName(injectTokens[index] || type);
394
- });
395
- }
396
- injectProperties(instance, target) {
397
- const autowiredProps = getMetaMap(METADATA.AUTOWIRED, target.prototype);
398
- for (const [prop, token] of autowiredProps) {
399
- const resolvedToken = token || getMethodMetaOrUndefined(METADATA.PROPERTY_TYPE, target.prototype, prop);
400
- if (resolvedToken) Object.defineProperty(instance, prop, {
401
- get: () => this.resolve(resolvedToken),
402
- enumerable: true,
403
- configurable: true
404
- });
405
- }
406
- const valueProps = getMetaMap(METADATA.VALUE, target.prototype);
407
- for (const [prop, config] of valueProps) Object.defineProperty(instance, prop, {
408
- get() {
409
- if (Container._envResolver) {
410
- const val = Container._envResolver(config.envKey);
411
- if (val !== void 0) return val;
412
- }
413
- const val = process.env[config.envKey];
414
- if (val !== void 0) return val;
415
- if (config.defaultValue !== void 0) return config.defaultValue;
416
- throw new Error(`@Value('${config.envKey}'): Environment variable "${config.envKey}" is not set and no default was provided.`);
417
- },
418
- enumerable: true,
419
- configurable: true
420
- });
421
- }
422
- };
423
- //#endregion
11
+ import { n as tokenName, t as Container } from "../container-B7jFEbPE.mjs";
424
12
  export { Container, tokenName };
425
-
426
- //# sourceMappingURL=container.mjs.map
@@ -1,3 +1,3 @@
1
1
 
2
- import { i as getCronJobs, n as Cron, r as CronJobMeta, t as CRON_META } from "../cron-RKhH5TOd.mjs";
2
+ import { i as getCronJobs, n as Cron, r as CronJobMeta, t as CRON_META } from "../cron-C29iHvHT.mjs";
3
3
  export { CRON_META, Cron, CronJobMeta, getCronJobs };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @forinda/kickjs v2.1.0
2
+ * @forinda/kickjs v2.2.0
3
3
  *
4
4
  * Copyright (c) Felix Orinda
5
5
  *
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * @license MIT
10
10
  */
11
- import { c as pushClassMeta, t as getClassMeta } from "../metadata-fmvikBA0.mjs";
11
+ import { c as pushClassMeta, t as getClassMeta } from "../metadata-BqXgNTOf.mjs";
12
12
  //#region src/core/cron.ts
13
13
  const CRON_META = Symbol("kick:cron");
14
14
  /**
@@ -1,3 +1,3 @@
1
1
 
2
- import { C as RouteDefinition, E as normalizeApiQueryParamsConfig, S as Repository, T as Value, _ as MiddlewareHandler, a as Builder, b as PostConstruct, c as Controller, d as FileUpload, f as FileUploadConfig, g as Middleware, h as Injectable, i as BaseUploadOptions, l as Delete, m as Inject, n as ApiQueryParamsConfig, o as ColumnApiQueryParamsConfig, p as Get, r as Autowired, s as Component, t as ApiQueryParams, u as FileTypeFilter, v as Patch, w as Service, x as Put, y as Post } from "../decorators-CQ93ak6Z.mjs";
3
- export { ApiQueryParams, ApiQueryParamsConfig, Autowired, BaseUploadOptions, Builder, ColumnApiQueryParamsConfig, Component, Controller, Delete, FileTypeFilter, FileUpload, FileUploadConfig, Get, Inject, Injectable, Middleware, MiddlewareHandler, Patch, Post, PostConstruct, Put, Repository, RouteDefinition, Service, Value, normalizeApiQueryParamsConfig };
2
+ import { C as Put, D as Value, E as Service, O as normalizeApiQueryParamsConfig, S as PostConstruct, T as RouteDefinition, _ as Injectable, a as Builder, b as Patch, c as Controller, d as EnvKey, f as FileTypeFilter, g as Inject, h as Get, i as BaseUploadOptions, l as Delete, m as FileUploadConfig, n as ApiQueryParamsConfig, o as ColumnApiQueryParamsConfig, p as FileUpload, r as Autowired, s as Component, t as ApiQueryParams, u as Env, v as Middleware, w as Repository, x as Post, y as MiddlewareHandler } from "../decorators-D3lBlmud.mjs";
3
+ export { ApiQueryParams, ApiQueryParamsConfig, Autowired, BaseUploadOptions, Builder, ColumnApiQueryParamsConfig, Component, Controller, Delete, Env, EnvKey, FileTypeFilter, FileUpload, FileUploadConfig, Get, Inject, Injectable, Middleware, MiddlewareHandler, Patch, Post, PostConstruct, Put, Repository, RouteDefinition, Service, Value, normalizeApiQueryParamsConfig };