@forinda/kickjs 5.0.2 → 5.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.
- package/dist/{adapter-6Pp4kFdM.d.mts → adapter-C1w_xt08.d.mts} +3 -3
- package/dist/{adapter-6Pp4kFdM.d.mts.map → adapter-C1w_xt08.d.mts.map} +1 -1
- package/dist/{app-module-Blgz4Rti.d.mts → app-module-D6zL_V5S.d.mts} +3 -3
- package/dist/{app-module-Blgz4Rti.d.mts.map → app-module-D6zL_V5S.d.mts.map} +1 -1
- package/dist/{application-CHvMXqbO.d.mts → application-BTRI4aBd.d.mts} +23 -6
- package/dist/application-BTRI4aBd.d.mts.map +1 -0
- package/dist/{application-BmCrQdPG.mjs → application-Bw87drVl.mjs} +39 -7
- package/dist/application-Bw87drVl.mjs.map +1 -0
- package/dist/{bootstrap-C6GpMEpX.d.mts → bootstrap-B4YrBipl.d.mts} +2 -2
- package/dist/{bootstrap-C6GpMEpX.d.mts.map → bootstrap-B4YrBipl.d.mts.map} +1 -1
- package/dist/{bootstrap-CUf7KAK-.mjs → bootstrap-CsQ7LE-W.mjs} +6 -6
- package/dist/{bootstrap-CUf7KAK-.mjs.map → bootstrap-CsQ7LE-W.mjs.map} +1 -1
- package/dist/config/index.d.mts +1 -1
- package/dist/config/index.mjs +3 -3
- package/dist/{config-B6z2ri6d.mjs → config-DKRN5fqC.mjs} +3 -3
- package/dist/{config-B6z2ri6d.mjs.map → config-DKRN5fqC.mjs.map} +1 -1
- package/dist/{container-CnWDsxi-.d.mts → container-BZKeHc5X.d.mts} +11 -2
- package/dist/{container-CnWDsxi-.d.mts.map → container-BZKeHc5X.d.mts.map} +1 -1
- package/dist/{container-Dn3ENJgH.mjs → container-C0FlgLNH.mjs} +104 -18
- package/dist/container-C0FlgLNH.mjs.map +1 -0
- package/dist/{context-kfiZcP7J.mjs → context-CDFiXWcV.mjs} +3 -3
- package/dist/{context-kfiZcP7J.mjs.map → context-CDFiXWcV.mjs.map} +1 -1
- package/dist/{context-decorator-DrPvQ9Ag.d.mts → context-decorator-Bca_BoRK.d.mts} +140 -15
- package/dist/context-decorator-Bca_BoRK.d.mts.map +1 -0
- package/dist/core/adapter.d.mts +1 -1
- package/dist/core/adapter.mjs +1 -1
- package/dist/core/app-module.d.mts +1 -1
- package/dist/core/app-module.mjs +1 -1
- package/dist/core/cache.mjs +1 -1
- package/dist/core/container.d.mts +1 -1
- package/dist/core/container.mjs +2 -2
- package/dist/core/cron.mjs +2 -2
- package/dist/core/decorators.d.mts +1 -1
- package/dist/core/decorators.mjs +3 -3
- package/dist/core/decorators.mjs.map +1 -1
- package/dist/core/errors.mjs +1 -1
- package/dist/core/interfaces.mjs +1 -1
- package/dist/core/logger.mjs +5 -3
- package/dist/core/logger.mjs.map +1 -1
- package/dist/core/path.mjs +1 -1
- package/dist/core/plugin.d.mts +1 -1
- package/dist/core/plugin.mjs +1 -1
- package/dist/core/reactivity.mjs +1 -1
- package/dist/{core-CLCy-u2-.mjs → core-K0J8AH_4.mjs} +111 -23
- package/dist/core-K0J8AH_4.mjs.map +1 -0
- package/dist/{decorators-BMvaLliz.d.mts → decorators-CRmHuzxz.d.mts} +2 -2
- package/dist/{decorators-BMvaLliz.d.mts.map → decorators-CRmHuzxz.d.mts.map} +1 -1
- package/dist/{env-B4asq48l.mjs → env-CDMCT10_.mjs} +11 -5
- package/dist/env-CDMCT10_.mjs.map +1 -0
- package/dist/http/application.d.mts +1 -1
- package/dist/http/application.mjs +2 -2
- package/dist/http/bootstrap.d.mts +1 -1
- package/dist/http/bootstrap.mjs +2 -2
- package/dist/http/context.mjs +2 -2
- package/dist/http/middleware/cors.mjs +1 -1
- package/dist/http/middleware/csrf.mjs +1 -1
- package/dist/http/middleware/error-handler.mjs +2 -2
- package/dist/http/middleware/helmet.mjs +1 -1
- package/dist/http/middleware/rate-limit.mjs +1 -1
- package/dist/http/middleware/request-id.mjs +1 -1
- package/dist/http/middleware/request-logger.mjs +2 -2
- package/dist/http/middleware/session.mjs +1 -1
- package/dist/http/middleware/spa.d.mts +1 -1
- package/dist/http/middleware/spa.mjs +3 -3
- package/dist/http/middleware/upload.d.mts +1 -1
- package/dist/http/middleware/upload.mjs +1 -1
- package/dist/http/middleware/validate.mjs +2 -2
- package/dist/http/middleware/views.d.mts +1 -1
- package/dist/http/middleware/views.mjs +2 -2
- package/dist/http/query/index.mjs +2 -2
- package/dist/http/router-builder.d.mts +1 -1
- package/dist/http/router-builder.mjs +5 -5
- package/dist/{index-D-qhXg9M.d.mts → index-DhNglXyS.d.mts} +2 -2
- package/dist/index-DhNglXyS.d.mts.map +1 -0
- package/dist/{index-Yhs9sTMW.d.mts → index-DvZfBNIf.d.mts} +60 -9
- package/dist/index-DvZfBNIf.d.mts.map +1 -0
- package/dist/index.d.mts +15 -15
- package/dist/index.mjs +30 -13
- package/dist/index.mjs.map +1 -1
- package/dist/logger-CLVRZf2N.d.mts.map +1 -1
- package/dist/{metadata-BqhX5q4E.mjs → metadata-DPLdmj1w.mjs} +2 -2
- package/dist/{metadata-BqhX5q4E.mjs.map → metadata-DPLdmj1w.mjs.map} +1 -1
- package/dist/{plugin-DDjoN4XI.d.mts → plugin-DF8Xfv9Z.d.mts} +5 -5
- package/dist/{plugin-DDjoN4XI.d.mts.map → plugin-DF8Xfv9Z.d.mts.map} +1 -1
- package/dist/{query-IvtMtXoI.mjs → query-CD0AMqxx.mjs} +2 -2
- package/dist/{query-IvtMtXoI.mjs.map → query-CD0AMqxx.mjs.map} +1 -1
- package/dist/{router-builder-zsX4Oq7c.d.mts → router-builder-C7sXk_FG.d.mts} +2 -2
- package/dist/{router-builder-zsX4Oq7c.d.mts.map → router-builder-C7sXk_FG.d.mts.map} +1 -1
- package/dist/{spa-CwIbdvPc.d.mts → spa-e4FIS2RB.d.mts} +2 -2
- package/dist/{spa-CwIbdvPc.d.mts.map → spa-e4FIS2RB.d.mts.map} +1 -1
- package/dist/{upload-BueOnnLw.d.mts → upload-BM9uyR6Y.d.mts} +2 -2
- package/dist/{upload-BueOnnLw.d.mts.map → upload-BM9uyR6Y.d.mts.map} +1 -1
- package/dist/{views-DhuvHYPA.d.mts → views-DkNp9JJs.d.mts} +4 -4
- package/dist/views-DkNp9JJs.d.mts.map +1 -0
- package/package.json +1 -1
- package/dist/application-BmCrQdPG.mjs.map +0 -1
- package/dist/application-CHvMXqbO.d.mts.map +0 -1
- package/dist/container-Dn3ENJgH.mjs.map +0 -1
- package/dist/context-decorator-DrPvQ9Ag.d.mts.map +0 -1
- package/dist/core-CLCy-u2-.mjs.map +0 -1
- package/dist/env-B4asq48l.mjs.map +0 -1
- package/dist/index-D-qhXg9M.d.mts.map +0 -1
- package/dist/index-Yhs9sTMW.d.mts.map +0 -1
- package/dist/views-DhuvHYPA.d.mts.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
import { i as Constructor, o as MaybePromise } from "./interfaces-B50n7dwl.mjs";
|
|
3
|
-
import { s as InjectionToken } from "./container-
|
|
3
|
+
import { s as InjectionToken } from "./container-BZKeHc5X.mjs";
|
|
4
4
|
import { n as ExecutionContext, r as MetaValue, t as ContextMeta } from "./execution-context-DKnt61pY.mjs";
|
|
5
5
|
//#region src/core/context-decorator.d.ts
|
|
6
6
|
/**
|
|
@@ -43,7 +43,7 @@ type ResolvedDeps<D extends Record<string, DepValue>> = { [K in keyof D]: D[K] e
|
|
|
43
43
|
* {@link ExecutionContext}; HTTP contributors typically
|
|
44
44
|
* default to `RequestContext` at the call site.
|
|
45
45
|
*/
|
|
46
|
-
interface ContextDecoratorSpec<K extends string = string, D extends Record<string, DepValue> = Record<string, never>, Ctx extends ExecutionContext = ExecutionContext> {
|
|
46
|
+
interface ContextDecoratorSpec<K extends string = string, D extends Record<string, DepValue> = Record<string, never>, P extends Record<string, unknown> = Record<string, never>, Ctx extends ExecutionContext = ExecutionContext> {
|
|
47
47
|
/** ContextMeta key the resolved value is written to. */
|
|
48
48
|
key: K;
|
|
49
49
|
/**
|
|
@@ -70,6 +70,35 @@ interface ContextDecoratorSpec<K extends string = string, D extends Record<strin
|
|
|
70
70
|
* and downstream consumers see `ctx.get(key) === undefined`.
|
|
71
71
|
*/
|
|
72
72
|
optional?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Default per-call params merged with the call-site params; call-site
|
|
75
|
+
* wins. When omitted, params default to `{}` and the resolver
|
|
76
|
+
* receives an empty object — back-compat with today's zero-arg
|
|
77
|
+
* decorators.
|
|
78
|
+
*
|
|
79
|
+
* Param shape is intentionally unconstrained: plain data, functions,
|
|
80
|
+
* and closures are all valid. Adopters who want runtime validation
|
|
81
|
+
* should perform it inside `resolve()` — keeps the framework
|
|
82
|
+
* validator-agnostic so projects can plug Zod / Valibot / hand-rolled
|
|
83
|
+
* checks without the framework caring.
|
|
84
|
+
*
|
|
85
|
+
* **Required-field caveat.** The factory call signature accepts
|
|
86
|
+
* `Partial<P>` so adopters can override only the fields they care
|
|
87
|
+
* about. If your `P` declares a *required* field that isn't in
|
|
88
|
+
* `paramDefaults`, the merged runtime value can be missing that
|
|
89
|
+
* field even though TypeScript types `params` as `P` inside
|
|
90
|
+
* `resolve()`. Mitigate by either:
|
|
91
|
+
*
|
|
92
|
+
* 1. Marking the field optional in `P` and `if`-checking inside
|
|
93
|
+
* `resolve()`, or
|
|
94
|
+
* 2. Providing a default for every required field in
|
|
95
|
+
* `paramDefaults`.
|
|
96
|
+
*
|
|
97
|
+
* The framework can't enforce option 2 at compile time without
|
|
98
|
+
* giving up the back-compat that lets `paramDefaults` be omitted
|
|
99
|
+
* entirely for `P = Record<string, never>`.
|
|
100
|
+
*/
|
|
101
|
+
paramDefaults?: Partial<P>;
|
|
73
102
|
/**
|
|
74
103
|
* Hook invoked when `resolve()` throws and `optional` is `false`.
|
|
75
104
|
* Returning a value writes it to `ctx.set(key, …)`; returning
|
|
@@ -78,10 +107,21 @@ interface ContextDecoratorSpec<K extends string = string, D extends Record<strin
|
|
|
78
107
|
*
|
|
79
108
|
* Async-permitted by design — adopters frequently want to
|
|
80
109
|
* `await auditService.log(err)` or `await cache.fallback(...)`.
|
|
110
|
+
*
|
|
111
|
+
* The third `params` argument carries the resolved per-call params
|
|
112
|
+
* (call-site overrides merged on top of `paramDefaults`).
|
|
81
113
|
*/
|
|
82
|
-
onError?: (err: unknown, ctx: Ctx) => MaybePromise<MetaValue<K> | undefined | void>;
|
|
83
|
-
/**
|
|
84
|
-
|
|
114
|
+
onError?: (err: unknown, ctx: Ctx, params: P) => MaybePromise<MetaValue<K> | undefined | void>;
|
|
115
|
+
/**
|
|
116
|
+
* Compute and return the value to write into `ctx.set(key, …)`.
|
|
117
|
+
*
|
|
118
|
+
* The third `params` argument carries the resolved per-call params
|
|
119
|
+
* (call-site overrides merged on top of `paramDefaults`). When the
|
|
120
|
+
* decorator is applied zero-arg (`@Foo`), `params` equals
|
|
121
|
+
* `paramDefaults` (or `{}` if defaults are omitted). When applied as
|
|
122
|
+
* a factory (`@Foo({ ... })`), the call-site object is merged on top.
|
|
123
|
+
*/
|
|
124
|
+
resolve: (ctx: Ctx, deps: ResolvedDeps<D>, params: P) => MaybePromise<MetaValue<K>>;
|
|
85
125
|
}
|
|
86
126
|
/**
|
|
87
127
|
* Internal, normalised registration produced by {@link defineContextDecorator}.
|
|
@@ -95,8 +135,21 @@ interface ContributorRegistration<K extends string = string, D extends Record<st
|
|
|
95
135
|
readonly deps: D;
|
|
96
136
|
readonly dependsOn: readonly ContextMetaKey[];
|
|
97
137
|
readonly optional: boolean;
|
|
98
|
-
|
|
99
|
-
|
|
138
|
+
/**
|
|
139
|
+
* Per-call params from the spec are baked into the closure at
|
|
140
|
+
* decorator-construction time, so the runner-facing `onError`
|
|
141
|
+
* exposes only `(err, ctx)`.
|
|
142
|
+
*/
|
|
143
|
+
readonly onError?: (err: unknown, ctx: Ctx) => MaybePromise<MetaValue<K> | undefined | void>;
|
|
144
|
+
/**
|
|
145
|
+
* Per-call params from the spec are baked into the closure at
|
|
146
|
+
* decorator-construction time, so the runner-facing `resolve`
|
|
147
|
+
* exposes only `(ctx, deps)`. Adopters who write their own
|
|
148
|
+
* registrations (without `defineContextDecorator`) match this
|
|
149
|
+
* shape directly — params are an implementation detail of the
|
|
150
|
+
* decorator factory, not of the runtime pipeline.
|
|
151
|
+
*/
|
|
152
|
+
readonly resolve: (ctx: Ctx, deps: ResolvedDeps<D>) => MaybePromise<MetaValue<K>>;
|
|
100
153
|
}
|
|
101
154
|
/**
|
|
102
155
|
* Type-erased registration shape used in the public collection slots
|
|
@@ -120,14 +173,86 @@ type AnyContributorRegistration = ContributorRegistration<string, any, any>;
|
|
|
120
173
|
/** Convenience alias for `AnyContributorRegistration[]` collections. */
|
|
121
174
|
type ContributorRegistrations = AnyContributorRegistration[] | readonly AnyContributorRegistration[];
|
|
122
175
|
/**
|
|
123
|
-
* The
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
176
|
+
* The decorator function returned by either a zero-arg
|
|
177
|
+
* {@link ContextDecorator} application or a factory call. Overloaded
|
|
178
|
+
* to satisfy both class and method decorator shapes — adopters apply
|
|
179
|
+
* the same decorator to either site without TS rejecting the call.
|
|
180
|
+
*/
|
|
181
|
+
interface ContextDecoratorTarget {
|
|
182
|
+
/** Class decorator usage. */
|
|
183
|
+
(target: Function): void;
|
|
184
|
+
/** Method decorator usage. */
|
|
185
|
+
(target: object, propertyKey: string | symbol, descriptor?: PropertyDescriptor): void;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* The value returned by {@link defineContextDecorator}. Callable as
|
|
189
|
+
* either a class or method decorator (with `paramDefaults` applied),
|
|
190
|
+
* as a factory (`@Foo({...})` returning a per-site decorator), or
|
|
191
|
+
* via `.with(params)` for non-decorator registration sites (module
|
|
192
|
+
* hooks, adapter hooks, bootstrap option). `.registration` exposes
|
|
193
|
+
* the underlying frozen {@link ContributorRegistration} for the
|
|
194
|
+
* default-params case.
|
|
127
195
|
*/
|
|
128
|
-
interface ContextDecorator<K extends string = string, D extends Record<string, DepValue> = Record<string, never>, Ctx extends ExecutionContext = ExecutionContext> {
|
|
129
|
-
|
|
196
|
+
interface ContextDecorator<K extends string = string, D extends Record<string, DepValue> = Record<string, never>, P extends Record<string, unknown> = Record<string, never>, Ctx extends ExecutionContext = ExecutionContext> {
|
|
197
|
+
/**
|
|
198
|
+
* Class decorator usage with `paramDefaults` — `@Foo class C {}`.
|
|
199
|
+
* The class constructor is a `Function`, so this overload only
|
|
200
|
+
* matches actual classes (not plain object literals — which
|
|
201
|
+
* fall through to the factory overload below).
|
|
202
|
+
*/
|
|
203
|
+
(target: Function): void;
|
|
204
|
+
/**
|
|
205
|
+
* Method decorator usage with `paramDefaults` — `@Foo` over a
|
|
206
|
+
* method. The required `propertyKey` distinguishes this from the
|
|
207
|
+
* factory overload's single-object-arg call shape.
|
|
208
|
+
*/
|
|
209
|
+
(target: object, propertyKey: string | symbol, descriptor?: PropertyDescriptor): void;
|
|
210
|
+
/**
|
|
211
|
+
* Zero-arg factory usage — `@Foo()` returns a decorator with
|
|
212
|
+
* `paramDefaults` applied. Equivalent in behaviour to the bare
|
|
213
|
+
* `@Foo` form, exposed here so adopters who prefer "always call the
|
|
214
|
+
* factory" don't need an `as any` cast.
|
|
215
|
+
*/
|
|
216
|
+
(): ContextDecoratorTarget;
|
|
217
|
+
/**
|
|
218
|
+
* Factory usage — `@Foo({ ... })` returns the actual decorator with
|
|
219
|
+
* call-site params merged onto `paramDefaults`. Matches a single
|
|
220
|
+
* params object; plain objects don't satisfy the `Function` /
|
|
221
|
+
* 2-arg-minimum constraints above, so TS picks this overload.
|
|
222
|
+
*
|
|
223
|
+
* Accepts `Partial<P>` so adopters can override only the fields
|
|
224
|
+
* they care about — anything missing falls back to `paramDefaults`
|
|
225
|
+
* at runtime. Inside `resolve()`, `params` is the fully merged
|
|
226
|
+
* `P`, never a `Partial<P>`.
|
|
227
|
+
*
|
|
228
|
+
* The returned decorator is overloaded for class AND method usage —
|
|
229
|
+
* `@Foo({...}) class C {}` and `@Foo({...}) m() {}` both type-check.
|
|
230
|
+
*/
|
|
231
|
+
(params: Partial<P>): ContextDecoratorTarget;
|
|
232
|
+
/**
|
|
233
|
+
* Bare registration — uses `paramDefaults` only. Use this at non-
|
|
234
|
+
* decorator registration sites (module / adapter / bootstrap) when
|
|
235
|
+
* the call site doesn't need to override params.
|
|
236
|
+
*/
|
|
130
237
|
readonly registration: ContributorRegistration<K, D, Ctx>;
|
|
238
|
+
/**
|
|
239
|
+
* Build a registration with call-site params merged onto
|
|
240
|
+
* `paramDefaults`. Use this at non-decorator registration sites
|
|
241
|
+
* when the call site DOES want to override params:
|
|
242
|
+
*
|
|
243
|
+
* ```ts
|
|
244
|
+
* bootstrap({
|
|
245
|
+
* contributors: [LoadTenant.with({ source: 'subdomain' }).registration],
|
|
246
|
+
* })
|
|
247
|
+
* ```
|
|
248
|
+
*
|
|
249
|
+
* `Partial<P>` for the same reason as the factory overload — the
|
|
250
|
+
* runtime merges with `paramDefaults`, so adopters only specify
|
|
251
|
+
* fields they want to override.
|
|
252
|
+
*/
|
|
253
|
+
with(params: Partial<P>): {
|
|
254
|
+
readonly registration: ContributorRegistration<K, D, Ctx>;
|
|
255
|
+
};
|
|
131
256
|
}
|
|
132
257
|
/**
|
|
133
258
|
* Define a typed context contributor.
|
|
@@ -155,7 +280,7 @@ interface ContextDecorator<K extends string = string, D extends Record<string, D
|
|
|
155
280
|
* metadata; the topo-sort, runner, and HTTP integration land in later
|
|
156
281
|
* phases. See `architecture.md` §20 for the full pipeline plan.
|
|
157
282
|
*/
|
|
158
|
-
declare function defineContextDecorator<K extends string, D extends Record<string, DepValue> = Record<string, never>, Ctx extends ExecutionContext = ExecutionContext>(spec: ContextDecoratorSpec<K, D, Ctx>): ContextDecorator<K, D, Ctx>;
|
|
283
|
+
declare function defineContextDecorator<K extends string, D extends Record<string, DepValue> = Record<string, never>, P extends Record<string, unknown> = Record<string, never>, Ctx extends ExecutionContext = ExecutionContext>(spec: ContextDecoratorSpec<K, D, P, Ctx>): ContextDecorator<K, D, P, Ctx>;
|
|
159
284
|
//#endregion
|
|
160
285
|
export { ContributorRegistration as a, ResolvedDeps as c, ContextMetaKey as i, defineContextDecorator as l, ContextDecorator as n, ContributorRegistrations as o, ContextDecoratorSpec as r, DepValue as s, AnyContributorRegistration as t };
|
|
161
|
-
//# sourceMappingURL=context-decorator-
|
|
286
|
+
//# sourceMappingURL=context-decorator-Bca_BoRK.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-decorator-Bca_BoRK.d.mts","names":[],"sources":["../src/core/context-decorator.ts"],"mappings":";;;;;;;AAkBA;;;;;AAUA;;;;;KAVY,cAAA,SAAuB,WAAA,gCAA2C,WAAA;;;;;;;;;KAUlE,QAAA,GAAW,cAAA,YAA0B,WAAA;;;;;;;;KASrC,YAAA,WAAuB,MAAA,SAAe,QAAA,mBACpC,CAAA,GAAI,CAAA,CAAE,CAAA,UAAW,cAAA,YACzB,CAAA,GACA,CAAA,CAAE,CAAA,UAAW,WAAA,YACX,CAAA;;;;;;;;;;;UAcS,oBAAA,sCAEL,MAAA,SAAe,QAAA,IAAY,MAAA,2BAC3B,MAAA,oBAA0B,MAAA,6BACxB,gBAAA,GAAmB,gBAAA;EAJhB;EAOf,GAAA,EAAK,CAAA;EAP8B;;;;;EAanC,IAAA,GAAO,CAAA;EATK;;;;;;;;;;;EAqBZ,SAAA,YAAqB,cAAA;EA0DN;;;;;EApDf,QAAA;EAoDyD;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAvBzD,aAAA,GAAgB,OAAA,CAAQ,CAAA;EAaW;;;;;;;;;;;;EAAnC,OAAA,IAAW,GAAA,WAAc,GAAA,EAAK,GAAA,EAAK,MAAA,EAAQ,CAAA,KAAM,YAAA,CAAa,SAAA,CAAU,CAAA;EAUF;;;;AAUxE;;;;;EAVE,OAAA,GAAU,GAAA,EAAK,GAAA,EAAK,IAAA,EAAM,YAAA,CAAa,CAAA,GAAI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AAQ,CAAA;IAAA,SAAgB,YAAA,EAAc,uBAAA,CAAwB,CAAA,EAAG,CAAA,EAAG,GAAA;EAAA;AAAA;;;;;;;AA6BnF;;;;;;;;;;;;;;;;;;;;iBAAgB,sBAAA,6BAEJ,MAAA,SAAe,QAAA,IAAY,MAAA,2BAC3B,MAAA,oBAA0B,MAAA,6BACxB,gBAAA,GAAmB,gBAAA,CAAA,CAC/B,IAAA,EAAM,oBAAA,CAAqB,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,GAAA,IAAO,gBAAA,CAAiB,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,GAAA"}
|
package/dist/core/adapter.d.mts
CHANGED
|
@@ -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-
|
|
2
|
+
import { a as MiddlewarePhase, i as AppAdapterClass, n as AdapterMiddleware, r as AppAdapter, t as AdapterContext } from "../adapter-C1w_xt08.mjs";
|
|
3
3
|
export { AdapterContext, AdapterMiddleware, AppAdapter, AppAdapterClass, MiddlewarePhase };
|
package/dist/core/adapter.mjs
CHANGED
package/dist/core/app-module.mjs
CHANGED
package/dist/core/cache.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
|
|
2
|
-
import { a as tokenName, i as KickJsRegistry, n as ContainerChangeEvent, r as ContainerChangeListener, t as Container } from "../container-
|
|
2
|
+
import { a as tokenName, i as KickJsRegistry, n as ContainerChangeEvent, r as ContainerChangeListener, t as Container } from "../container-BZKeHc5X.mjs";
|
|
3
3
|
export { Container, ContainerChangeEvent, ContainerChangeListener, KickJsRegistry, tokenName };
|
package/dist/core/container.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @forinda/kickjs v5.0
|
|
2
|
+
* @forinda/kickjs v5.2.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Felix Orinda
|
|
5
5
|
*
|
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
import { n as tokenName, t as Container } from "../container-
|
|
11
|
+
import { n as tokenName, t as Container } from "../container-C0FlgLNH.mjs";
|
|
12
12
|
export { Container, tokenName };
|
package/dist/core/cron.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @forinda/kickjs v5.0
|
|
2
|
+
* @forinda/kickjs v5.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-
|
|
11
|
+
import { c as pushClassMeta, t as getClassMeta } from "../metadata-DPLdmj1w.mjs";
|
|
12
12
|
//#region src/core/cron.ts
|
|
13
13
|
const CRON_META = "kick/cron";
|
|
14
14
|
/**
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
|
|
2
|
-
import { A as normalizeApiQueryParamsConfig, C as Post, D as RouteDefinition, E as Repository, O as Service, S as Patch, T as Put, _ as Get, a as Autowired, b as Middleware, c as ColumnApiQueryParamsConfig, d as Delete, f as Env, g as FileUploadConfig, h as FileUpload, i as AssetKey, k as Value, l as Component, m as FileTypeFilter, n as ApiQueryParamsConfig, o as BaseUploadOptions, p as EnvKey, r as Asset, s as Builder, t as ApiQueryParams, u as Controller, v as Inject, w as PostConstruct, x as MiddlewareHandler, y as Injectable } from "../decorators-
|
|
2
|
+
import { A as normalizeApiQueryParamsConfig, C as Post, D as RouteDefinition, E as Repository, O as Service, S as Patch, T as Put, _ as Get, a as Autowired, b as Middleware, c as ColumnApiQueryParamsConfig, d as Delete, f as Env, g as FileUploadConfig, h as FileUpload, i as AssetKey, k as Value, l as Component, m as FileTypeFilter, n as ApiQueryParamsConfig, o as BaseUploadOptions, p as EnvKey, r as Asset, s as Builder, t as ApiQueryParams, u as Controller, v as Inject, w as PostConstruct, x as MiddlewareHandler, y as Injectable } from "../decorators-CRmHuzxz.mjs";
|
|
3
3
|
export { ApiQueryParams, ApiQueryParamsConfig, Asset, AssetKey, 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 };
|
package/dist/core/decorators.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @forinda/kickjs v5.0
|
|
2
|
+
* @forinda/kickjs v5.2.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Felix Orinda
|
|
5
5
|
*
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
import { t as Container } from "../container-
|
|
11
|
+
import { t as Container } from "../container-C0FlgLNH.mjs";
|
|
12
12
|
import { METADATA, Scope } from "./interfaces.mjs";
|
|
13
|
-
import { c as pushClassMeta, d as setInMetaMap, f as setInMetaRecord, l as pushMethodMeta, p as setMethodMeta, u as setClassMeta } from "../metadata-
|
|
13
|
+
import { c as pushClassMeta, d as setInMetaMap, f as setInMetaRecord, l as pushMethodMeta, p as setMethodMeta, u as setClassMeta } from "../metadata-DPLdmj1w.mjs";
|
|
14
14
|
import "reflect-metadata";
|
|
15
15
|
//#region src/core/decorators.ts
|
|
16
16
|
const pendingRegistrations = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.mjs","names":[],"sources":["../../src/core/decorators.ts"],"sourcesContent":["import 'reflect-metadata'\nimport { METADATA, Scope, type ServiceOptions } from './interfaces'\nimport { Container, type KickJsRegistry } from './container'\nimport {\n setClassMeta,\n setMethodMeta,\n getClassMeta,\n pushClassMeta,\n pushMethodMeta,\n setInMetaMap,\n setInMetaRecord,\n} from './metadata'\n\n// ── Decorator Registration System ───────────────────────────────────────\n// Decorators execute at class-definition time (module load). The Container\n// may not exist yet when the first decorator fires. We queue registrations\n// and flush them on first Container.getInstance() call.\n//\n// `allRegistrations` is a persistent registry that survives Container.reset().\n// On reset (HMR), all previously decorated classes are re-registered on the\n// fresh container. This ensures @Service, @Controller, @Repository, etc.\n// all survive HMR without manual re-registration.\n\ntype PendingRegistration = { target: any; scope: Scope }\nconst pendingRegistrations: PendingRegistration[] = []\n// Keyed by class name to prevent memory leaks during HMR — new class with\n// the same name replaces the old entry instead of accumulating references.\nconst allRegistrations = new Map<string, { target: any; scope: Scope }>()\nlet containerRef: any = null\n\nfunction flushPending(container: any): void {\n containerRef = container\n for (const { target, scope } of pendingRegistrations) {\n if (!container.has(target)) {\n container.register(target, target, scope)\n }\n }\n pendingRegistrations.length = 0\n}\n\n// Wire up synchronously — Container._onReady is called on first getInstance()\nContainer._onReady = flushPending\n\n// On Container.reset(), update containerRef and replay ALL decorator\n// registrations on the fresh container. This handles HMR where the container\n// is wiped but not all decorated modules are re-evaluated.\nContainer._onReset = (container: any) => {\n containerRef = container\n for (const [, { target, scope }] of allRegistrations) {\n if (!container.has(target)) {\n container.register(target, target, scope)\n }\n }\n}\n\n// ── Class Decorators ────────────────────────────────────────────────────\n\nfunction registerInContainer(target: any, scope: Scope): void {\n setClassMeta(METADATA.INJECTABLE, true, target)\n setClassMeta(METADATA.SCOPE, scope, target)\n\n // Track in persistent registry — survives Container.reset() for HMR replay.\n // Keyed by name so HMR class re-creation replaces the old entry.\n const name = target.name || String(target)\n allRegistrations.set(name, { target, scope })\n\n if (containerRef) {\n // Container already initialized — register immediately\n if (!containerRef.has(target)) {\n containerRef.register(target, target, scope)\n }\n } else {\n // Container not ready yet — queue for later\n pendingRegistrations.push({ target, scope })\n }\n}\n\n/** Mark a class as injectable with lifecycle scope */\nexport function Injectable(options?: ServiceOptions): ClassDecorator {\n return (target: any) => {\n setClassMeta(METADATA.CLASS_KIND, 'injectable', target)\n registerInContainer(target, options?.scope ?? Scope.SINGLETON)\n }\n}\n\n/** Mark a class as a service (semantic alias for Injectable) */\nexport function Service(options?: ServiceOptions): ClassDecorator {\n return (target: any) => {\n setClassMeta(METADATA.CLASS_KIND, 'service', target)\n registerInContainer(target, options?.scope ?? Scope.SINGLETON)\n }\n}\n\n/** Mark a class as a generic managed component */\nexport function Component(options?: ServiceOptions): ClassDecorator {\n return (target: any) => {\n setClassMeta(METADATA.CLASS_KIND, 'component', target)\n registerInContainer(target, options?.scope ?? Scope.SINGLETON)\n }\n}\n\n/** Mark a class as a repository */\nexport function Repository(options?: ServiceOptions): ClassDecorator {\n return (target: any) => {\n setClassMeta(METADATA.CLASS_KIND, 'repository', target)\n registerInContainer(target, options?.scope ?? Scope.SINGLETON)\n }\n}\n\n/**\n * Mark a class as an HTTP controller and register it in the DI container.\n *\n * Route prefixes are defined by the module's `routes().path` — the single\n * source of truth for where routes mount. The legacy\n * `@Controller('/path')` parameter was removed in v4; if your code\n * still passes a string, see `docs/guide/migration-v3-to-v4.md` for\n * the rename map.\n */\nexport function Controller(): ClassDecorator {\n return (target: any) => {\n setClassMeta(METADATA.CLASS_KIND, 'controller', target)\n registerInContainer(target, Scope.SINGLETON)\n }\n}\n\n// ── Method Decorators ───────────────────────────────────────────────────\n\n/** Mark a method as a lifecycle hook called after instantiation */\nexport function PostConstruct(): MethodDecorator {\n return (target, propertyKey) => {\n setClassMeta(METADATA.POST_CONSTRUCT, propertyKey, target)\n }\n}\n\n// ── Property Decorators ─────────────────────────────────────────────────\n\n/** Property injection — resolved lazily from the container */\nexport function Autowired(token?: any): PropertyDecorator {\n return (target, propertyKey) => {\n setInMetaMap(METADATA.AUTOWIRED, target, propertyKey as string, token)\n }\n}\n\n/**\n * Constructor parameter injection with an explicit token.\n *\n * **Constructor parameters only** — does not work as a property decorator.\n * For property injection with a token, use `@Autowired(token)` instead.\n *\n * ## Typed string-literal overload (architecture.md §22.4 #3)\n *\n * When called with a string literal that matches a key of the\n * augmented `KickJsRegistry`, TypeScript narrows the parameter type\n * to the registered type. Typo'd literals become compile errors\n * (the string isn't `keyof KickJsRegistry`). Class identities and\n * `InjectionToken<T>` keep working unchanged via the second overload.\n *\n * @example\n * ```ts\n * import { Service, Inject } from '@forinda/kickjs'\n * import type { PrismaClient } from '@prisma/client'\n *\n * `@Service()`\n * class UserRepo {\n * constructor(@Inject('kick/prisma/Client') private db: PrismaClient) {}\n * }\n * ```\n *\n * After `kick typegen` populates `.kickjs/types/registry.d.ts` the\n * literal autocompletes from the registry, and a typo\n * (`@Inject('kick/prisma/Cleint')`) becomes a TS2345 error.\n */\nexport function Inject<K extends keyof KickJsRegistry & string>(token: K): ParameterDecorator\nexport function Inject(token: unknown): ParameterDecorator\nexport function Inject(token: unknown): ParameterDecorator {\n return (target, _propertyKey, parameterIndex) => {\n setInMetaRecord(METADATA.INJECT, target as object, parameterIndex, token)\n }\n}\n\n/**\n * Global ambient registry of typed environment variables, populated by\n * `kick typegen` from the project's env schema (typically\n * `src/env.ts`'s `export default defineEnv(...)`).\n *\n * Empty by default — declarations come from `.kickjs/types/env.ts`\n * generated alongside the rest of the typegen output. Once populated,\n * `@Value('PORT')` autocompletes the key, type-checks the default\n * value, and `process.env.PORT` is also typed via the parallel\n * `NodeJS.ProcessEnv` augmentation in the same generated file.\n */\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n interface KickEnv {}\n}\n\n/** A string key known to the typed env registry (`never` until typegen runs) */\nexport type EnvKey = keyof KickEnv & string\n\n/**\n * Look up the type of a typed env entry.\n *\n * Decorators can't propagate the property type from the key, so users\n * still need to write the property's type — but `Env<K>` lets them\n * derive it from `KickEnv` instead of duplicating the schema:\n *\n * ```ts\n * @Service()\n * class MyService {\n * @Value('PORT')\n * private port!: Env<'PORT'> // → number, narrowed from KickEnv['PORT']\n * }\n * ```\n */\nexport type Env<K extends EnvKey = EnvKey> = KickEnv[K]\n\n/**\n * Constraint that allows any string when the typed env registry is\n * empty (no `kick typegen` has run yet, so existing code with raw\n * string keys keeps working) but locks the argument down to known\n * `EnvKey` literals once the registry is populated.\n *\n * Implementation: when `EnvKey` is `never`, the conditional resolves\n * to the user's `K`, accepting anything. Once typegen has populated\n * `KickEnv`, `EnvKey` becomes a real union and the conditional forces\n * `K` to be assignable to it.\n */\ntype ValueKey<K extends string> = [EnvKey] extends [never] ? K : K & EnvKey\n\n/**\n * Inject an environment variable value. Evaluated lazily so the env\n * is available at access time, not at decoration time.\n *\n * If no default is provided and the env var is missing, throws at access time\n * to catch misconfiguration early instead of returning undefined.\n *\n * Uses metadata + instance getter to work correctly with `useDefineForClassFields`.\n *\n * Type-safety:\n * - Without `kick typegen` run, any string key is accepted (back-compat).\n * - After typegen, `KickEnv` is populated and unknown keys become a tsc\n * error. The optional `defaultValue` is type-checked against the\n * schema's inferred type for that key.\n */\nexport function Value<K extends string>(\n envKey: ValueKey<K>,\n defaultValue?: K extends EnvKey ? KickEnv[K] : unknown,\n): PropertyDecorator {\n return (target, propertyKey) => {\n setInMetaMap(METADATA.VALUE, target, propertyKey as string, { envKey, defaultValue })\n }\n}\n\n// ── @Asset — typed asset path injection (assets-plan.md PR 3+) ─────────\n\nimport type { KickAssets } from './assets'\n\n/**\n * Flatten the nested `KickAssets` augmentation (typegen-emitted in\n * PR 4) into a string-literal union of dot/slash-joined paths.\n *\n * `interface KickAssets { mails: { welcome: () => string; orders: {\n * confirmation: () => string } } }` becomes\n * `'mails/welcome' | 'mails/orders/confirmation'`.\n *\n * Returns `never` when `KickAssets` is empty (no typegen has run yet)\n * so `AssetKeyArg` falls through to accept any string.\n */\ntype FlattenAssets<T, Prefix extends string = ''> = {\n [K in keyof T & string]: T[K] extends () => string\n ? `${Prefix}${K}`\n : T[K] extends Record<string, unknown>\n ? FlattenAssets<T[K], `${Prefix}${K}/`>\n : never\n}[keyof T & string]\n\n/** Flat union of every known `<namespace>/<key>` path. */\nexport type AssetKey = FlattenAssets<KickAssets>\n\n/**\n * Constraint mirroring `ValueKey<K>` — accepts any string when\n * `AssetKey` is `never` (back-compat for adopters who haven't run\n * `kick typegen` yet) but locks the argument to known literals once\n * the typegen-augmented `KickAssets` interface is populated.\n */\ntype AssetKeyArg<K extends string> = [AssetKey] extends [never] ? K : K & AssetKey\n\n/**\n * Inject the resolved file-system path for a typed asset. Mirrors\n * `@Value`'s lazy-getter pattern — the asset is resolved on every\n * property access, NOT at class instantiation, so:\n *\n * - Tests can swap fixtures + clear the cache without re-instantiating\n * the consuming class.\n * - The first access cost is paid once per process (the manifest cache\n * in `core/assets.ts` makes subsequent calls cheap).\n *\n * Type-safety:\n *\n * - Without typegen, any string key is accepted (back-compat — same\n * trick as `@Value`).\n * - After typegen, `KickAssets` is populated and `AssetKey` is a\n * union of every flattened `<namespace>/<key>` path. Unknown keys\n * become a TS error.\n *\n * @example\n * ```ts\n * import { Service, Asset } from '@forinda/kickjs'\n *\n * `@Service()`\n * class MailService {\n * `@Asset('mails/welcome')`\n * private welcomeTemplate!: string\n *\n * send(user: User) {\n * return ejs.renderFile(this.welcomeTemplate, { user })\n * }\n * }\n * ```\n */\nexport function Asset<K extends string>(assetKey: AssetKeyArg<K>): PropertyDecorator {\n return (target, propertyKey) => {\n setInMetaMap(METADATA.ASSET, target, propertyKey as string, { assetKey })\n }\n}\n\n// ── HTTP Route Decorators ───────────────────────────────────────────────\n\nexport interface RouteDefinition {\n method: string\n path: string\n handlerName: string\n validation?: {\n /** JSON Schema object for validating the request body */\n body?: any\n /** JSON Schema object for validating query parameters */\n query?: any\n /** JSON Schema object for validating URL params */\n params?: any\n /** Schema name in OpenAPI components/schemas for the request body. Auto-generated from handler name if omitted. */\n name?: string\n }\n}\n\nfunction createRouteDecorator(method: string) {\n return (path?: string, validation?: RouteDefinition['validation']): MethodDecorator => {\n return (target, propertyKey) => {\n pushClassMeta<RouteDefinition>(METADATA.ROUTES, target.constructor, {\n method,\n path: path || '/',\n handlerName: propertyKey as string,\n validation,\n })\n }\n }\n}\n\nexport const Get = createRouteDecorator('GET')\nexport const Post = createRouteDecorator('POST')\nexport const Put = createRouteDecorator('PUT')\nexport const Delete = createRouteDecorator('DELETE')\nexport const Patch = createRouteDecorator('PATCH')\n\n// ── Query Params Decorator ─────────────────────────────────────────────\n\nexport interface ApiQueryParamsConfig {\n /** Fields that can be used in filter queries (e.g., `?filter=status:eq:active`) */\n filterable?: string[]\n /** Fields that can be used in sort queries (e.g., `?sort=createdAt:desc`) */\n sortable?: string[]\n /** Fields that are searched with the `?q=` parameter */\n searchable?: string[]\n}\n\n/**\n * Column-object-based query params config (e.g., from DrizzleQueryParamsConfig).\n * `Object.keys()` is used to derive field names for OpenAPI docs.\n */\nexport interface ColumnApiQueryParamsConfig {\n columns: Record<string, any>\n sortable?: Record<string, any>\n searchColumns?: any[]\n [key: string]: any\n}\n\n/**\n * Normalize a query params config to the string-based ApiQueryParamsConfig.\n * Handles both string-based and column-object-based configs.\n */\nexport function normalizeApiQueryParamsConfig(\n config: ApiQueryParamsConfig | ColumnApiQueryParamsConfig,\n): ApiQueryParamsConfig {\n if ('columns' in config && config.columns && typeof config.columns === 'object') {\n return {\n filterable: Object.keys(config.columns),\n sortable: config.sortable ? Object.keys(config.sortable) : undefined,\n searchable: config.searchColumns\n ? config.searchColumns.map((col: any) => col?.name ?? '').filter(Boolean)\n : undefined,\n }\n }\n return config as ApiQueryParamsConfig\n}\n\n/**\n * Document the query parameters accepted by a GET endpoint.\n * Used by SwaggerAdapter to generate `filter`, `sort`, `page`, `limit`, and `q` params\n * in the OpenAPI spec, with descriptions listing the allowed fields.\n *\n * Accepts both string-based configs and column-object configs (e.g., DrizzleQueryParamsConfig).\n *\n * @example\n * ```ts\n * // String-based\n * @ApiQueryParams({\n * filterable: ['status', 'category', 'price'],\n * sortable: ['name', 'createdAt', 'price'],\n * searchable: ['name', 'description'],\n * })\n *\n * // Column-object-based (Drizzle)\n * @ApiQueryParams(TASK_QUERY_CONFIG)\n * ```\n */\nexport function ApiQueryParams(\n config: ApiQueryParamsConfig | ColumnApiQueryParamsConfig,\n): MethodDecorator {\n return (target, propertyKey) => {\n const normalized = normalizeApiQueryParamsConfig(config)\n setMethodMeta(METADATA.QUERY_PARAMS, normalized, target.constructor, propertyKey as string)\n }\n}\n\n// ── Middleware Decorators ───────────────────────────────────────────────\n\n/**\n * Middleware handler function.\n * Generic `TCtx` defaults to `any` — import `RequestContext` from\n * `@forinda/kickjs` for full type safety:\n *\n * ```ts\n * import type { MiddlewareHandler } from '@forinda/kickjs'\n * import type { RequestContext } from '@forinda/kickjs'\n *\n * const auth: MiddlewareHandler<RequestContext> = (ctx, next) => {\n * ctx.body // fully typed\n * next()\n * }\n * ```\n */\nexport type MiddlewareHandler<TCtx = any> = (ctx: TCtx, next: () => void) => void | Promise<void>\n\n/** Attach middleware handlers to a class or method */\nexport function Middleware(...handlers: MiddlewareHandler[]): ClassDecorator & MethodDecorator {\n return (target: any, propertyKey?: string | symbol) => {\n if (propertyKey) {\n pushMethodMeta(\n METADATA.METHOD_MIDDLEWARES,\n target.constructor,\n propertyKey as string,\n ...handlers,\n )\n } else {\n pushClassMeta(METADATA.CLASS_MIDDLEWARES, target, ...handlers)\n }\n }\n}\n\n// ── File Upload Decorator ───────────────────────────────────────────────\n\n/**\n * File filter — accepts short extensions ('jpg'), full MIME types ('image/jpeg'),\n * wildcards ('image/*'), or a function `(mimetype, filename) => boolean` for full control.\n */\nexport type FileTypeFilter = string[] | ((mimetype: string, filename: string) => boolean)\n\n/**\n * Shared upload options used by both the `@FileUpload` decorator and the\n * `upload.single()` / `upload.array()` / `upload.none()` middleware.\n */\nexport interface BaseUploadOptions {\n /** Max file size in bytes (default: 5MB) */\n maxSize?: number\n /**\n * Allowed file types:\n * - **string[]** — short extensions ('jpg'), full MIME types ('image/jpeg'), or wildcards ('image/*')\n * - **function** — `(mimetype, filename) => boolean` for full control\n */\n allowedTypes?: FileTypeFilter\n /** Extend the built-in extension-to-MIME map */\n customMimeMap?: Record<string, string>\n}\n\nexport interface FileUploadConfig extends BaseUploadOptions {\n mode: 'single' | 'array' | 'none'\n /** Form field name (default: 'file') */\n fieldName?: string\n /** Max files for array mode (default: 10) */\n maxCount?: number\n}\n\n/** Configure file upload handling for a controller method */\nexport function FileUpload(config: FileUploadConfig): MethodDecorator {\n return (target, propertyKey) => {\n setMethodMeta(METADATA.FILE_UPLOAD, config, target.constructor, propertyKey as string)\n }\n}\n\n// ── Builder Decorator ───────────────────────────────────────────────────\n\n/** Add a static builder() method for fluent construction */\nexport function Builder(target: any): void {\n setClassMeta(METADATA.BUILDER, true, target)\n\n target.builder = function () {\n const props: Record<string, any> = {}\n const proxy: any = new Proxy(\n {},\n {\n get(_, key) {\n if (key === 'build') {\n return () => Object.assign(new target(), props)\n }\n return (value: any) => {\n props[key as string] = value\n return proxy\n }\n },\n },\n )\n return proxy\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAwBA,MAAM,uBAA8C,EAAE;AAGtD,MAAM,mCAAmB,IAAI,KAA4C;AACzE,IAAI,eAAoB;AAExB,SAAS,aAAa,WAAsB;AAC1C,gBAAe;AACf,MAAK,MAAM,EAAE,QAAQ,WAAW,qBAC9B,KAAI,CAAC,UAAU,IAAI,OAAO,CACxB,WAAU,SAAS,QAAQ,QAAQ,MAAM;AAG7C,sBAAqB,SAAS;;AAIhC,UAAU,WAAW;AAKrB,UAAU,YAAY,cAAmB;AACvC,gBAAe;AACf,MAAK,MAAM,GAAG,EAAE,QAAQ,YAAY,iBAClC,KAAI,CAAC,UAAU,IAAI,OAAO,CACxB,WAAU,SAAS,QAAQ,QAAQ,MAAM;;AAO/C,SAAS,oBAAoB,QAAa,OAAoB;AAC5D,cAAa,SAAS,YAAY,MAAM,OAAO;AAC/C,cAAa,SAAS,OAAO,OAAO,OAAO;CAI3C,MAAM,OAAO,OAAO,QAAQ,OAAO,OAAO;AAC1C,kBAAiB,IAAI,MA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AW,QAA2C;AACpE,SAAQ,QAAQ,gBAAgB;AAC9B,gBAAc,SAAS,aAAa,QAAQ,OAAO,aAAa,YAAsB;;;;AAO1F,SAAgB,QAAQ,QAAmB;AACzC,cAAa,SAAS,SAAS,MAAM,OAAO;AAE5C,QAAO,UAAU,WAAY;EAC3B,MAAM,QAA6B,EAAE;EACrC,MAAM,QAAa,IAAI,MACrB,EAAE,EACF,EACE,IAAI,GAAG,KAAK;AACV,OAAI,QAAQ,QACV,cAAa,OAAO,OAAO,IAAI,QAAQ,EAAE,MAAM;AAEjD,WAAQ,UAAe;AACrB,UAAM,OAAiB;AACvB,WAAO;;KAGZ,CACF;AACD,SAAO"}
|
|
1
|
+
{"version":3,"file":"decorators.mjs","names":[],"sources":["../../src/core/decorators.ts"],"sourcesContent":["import 'reflect-metadata'\nimport { METADATA, Scope, type ServiceOptions } from './interfaces'\nimport { Container, type KickJsRegistry } from './container'\nimport {\n setClassMeta,\n setMethodMeta,\n pushClassMeta,\n pushMethodMeta,\n setInMetaMap,\n setInMetaRecord,\n} from './metadata'\n\n// ── Decorator Registration System ───────────────────────────────────────\n// Decorators execute at class-definition time (module load). The Container\n// may not exist yet when the first decorator fires. We queue registrations\n// and flush them on first Container.getInstance() call.\n//\n// `allRegistrations` is a persistent registry that survives Container.reset().\n// On reset (HMR), all previously decorated classes are re-registered on the\n// fresh container. This ensures @Service, @Controller, @Repository, etc.\n// all survive HMR without manual re-registration.\n\ntype PendingRegistration = { target: any; scope: Scope }\nconst pendingRegistrations: PendingRegistration[] = []\n// Keyed by class name to prevent memory leaks during HMR — new class with\n// the same name replaces the old entry instead of accumulating references.\nconst allRegistrations = new Map<string, { target: any; scope: Scope }>()\nlet containerRef: any = null\n\nfunction flushPending(container: any): void {\n containerRef = container\n for (const { target, scope } of pendingRegistrations) {\n if (!container.has(target)) {\n container.register(target, target, scope)\n }\n }\n pendingRegistrations.length = 0\n}\n\n// Wire up synchronously — Container._onReady is called on first getInstance()\nContainer._onReady = flushPending\n\n// On Container.reset(), update containerRef and replay ALL decorator\n// registrations on the fresh container. This handles HMR where the container\n// is wiped but not all decorated modules are re-evaluated.\nContainer._onReset = (container: any) => {\n containerRef = container\n for (const [, { target, scope }] of allRegistrations) {\n if (!container.has(target)) {\n container.register(target, target, scope)\n }\n }\n}\n\n// ── Class Decorators ────────────────────────────────────────────────────\n\nfunction registerInContainer(target: any, scope: Scope): void {\n setClassMeta(METADATA.INJECTABLE, true, target)\n setClassMeta(METADATA.SCOPE, scope, target)\n\n // Track in persistent registry — survives Container.reset() for HMR replay.\n // Keyed by name so HMR class re-creation replaces the old entry.\n const name = target.name || String(target)\n allRegistrations.set(name, { target, scope })\n\n if (containerRef) {\n // Container already initialized — register immediately\n if (!containerRef.has(target)) {\n containerRef.register(target, target, scope)\n }\n } else {\n // Container not ready yet — queue for later\n pendingRegistrations.push({ target, scope })\n }\n}\n\n/** Mark a class as injectable with lifecycle scope */\nexport function Injectable(options?: ServiceOptions): ClassDecorator {\n return (target: any) => {\n setClassMeta(METADATA.CLASS_KIND, 'injectable', target)\n registerInContainer(target, options?.scope ?? Scope.SINGLETON)\n }\n}\n\n/** Mark a class as a service (semantic alias for Injectable) */\nexport function Service(options?: ServiceOptions): ClassDecorator {\n return (target: any) => {\n setClassMeta(METADATA.CLASS_KIND, 'service', target)\n registerInContainer(target, options?.scope ?? Scope.SINGLETON)\n }\n}\n\n/** Mark a class as a generic managed component */\nexport function Component(options?: ServiceOptions): ClassDecorator {\n return (target: any) => {\n setClassMeta(METADATA.CLASS_KIND, 'component', target)\n registerInContainer(target, options?.scope ?? Scope.SINGLETON)\n }\n}\n\n/** Mark a class as a repository */\nexport function Repository(options?: ServiceOptions): ClassDecorator {\n return (target: any) => {\n setClassMeta(METADATA.CLASS_KIND, 'repository', target)\n registerInContainer(target, options?.scope ?? Scope.SINGLETON)\n }\n}\n\n/**\n * Mark a class as an HTTP controller and register it in the DI container.\n *\n * Route prefixes are defined by the module's `routes().path` — the single\n * source of truth for where routes mount. The legacy\n * `@Controller('/path')` parameter was removed in v4; if your code\n * still passes a string, see `docs/guide/migration-v3-to-v4.md` for\n * the rename map.\n */\nexport function Controller(): ClassDecorator {\n return (target: any) => {\n setClassMeta(METADATA.CLASS_KIND, 'controller', target)\n registerInContainer(target, Scope.SINGLETON)\n }\n}\n\n// ── Method Decorators ───────────────────────────────────────────────────\n\n/** Mark a method as a lifecycle hook called after instantiation */\nexport function PostConstruct(): MethodDecorator {\n return (target, propertyKey) => {\n setClassMeta(METADATA.POST_CONSTRUCT, propertyKey, target)\n }\n}\n\n// ── Property Decorators ─────────────────────────────────────────────────\n\n/** Property injection — resolved lazily from the container */\nexport function Autowired(token?: any): PropertyDecorator {\n return (target, propertyKey) => {\n setInMetaMap(METADATA.AUTOWIRED, target, propertyKey as string, token)\n }\n}\n\n/**\n * Constructor parameter injection with an explicit token.\n *\n * **Constructor parameters only** — does not work as a property decorator.\n * For property injection with a token, use `@Autowired(token)` instead.\n *\n * ## Typed string-literal overload (architecture.md §22.4 #3)\n *\n * When called with a string literal that matches a key of the\n * augmented `KickJsRegistry`, TypeScript narrows the parameter type\n * to the registered type. Typo'd literals become compile errors\n * (the string isn't `keyof KickJsRegistry`). Class identities and\n * `InjectionToken<T>` keep working unchanged via the second overload.\n *\n * @example\n * ```ts\n * import { Service, Inject } from '@forinda/kickjs'\n * import type { PrismaClient } from '@prisma/client'\n *\n * `@Service()`\n * class UserRepo {\n * constructor(@Inject('kick/prisma/Client') private db: PrismaClient) {}\n * }\n * ```\n *\n * After `kick typegen` populates `.kickjs/types/registry.d.ts` the\n * literal autocompletes from the registry, and a typo\n * (`@Inject('kick/prisma/Cleint')`) becomes a TS2345 error.\n */\nexport function Inject<K extends keyof KickJsRegistry & string>(token: K): ParameterDecorator\nexport function Inject(token: unknown): ParameterDecorator\nexport function Inject(token: unknown): ParameterDecorator {\n return (target, _propertyKey, parameterIndex) => {\n setInMetaRecord(METADATA.INJECT, target as object, parameterIndex, token)\n }\n}\n\n/**\n * Global ambient registry of typed environment variables, populated by\n * `kick typegen` from the project's env schema (typically\n * `src/env.ts`'s `export default defineEnv(...)`).\n *\n * Empty by default — declarations come from `.kickjs/types/env.ts`\n * generated alongside the rest of the typegen output. Once populated,\n * `@Value('PORT')` autocompletes the key, type-checks the default\n * value, and `process.env.PORT` is also typed via the parallel\n * `NodeJS.ProcessEnv` augmentation in the same generated file.\n */\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n interface KickEnv {}\n}\n\n/** A string key known to the typed env registry (`never` until typegen runs) */\nexport type EnvKey = keyof KickEnv & string\n\n/**\n * Look up the type of a typed env entry.\n *\n * Decorators can't propagate the property type from the key, so users\n * still need to write the property's type — but `Env<K>` lets them\n * derive it from `KickEnv` instead of duplicating the schema:\n *\n * ```ts\n * @Service()\n * class MyService {\n * @Value('PORT')\n * private port!: Env<'PORT'> // → number, narrowed from KickEnv['PORT']\n * }\n * ```\n */\nexport type Env<K extends EnvKey = EnvKey> = KickEnv[K]\n\n/**\n * Constraint that allows any string when the typed env registry is\n * empty (no `kick typegen` has run yet, so existing code with raw\n * string keys keeps working) but locks the argument down to known\n * `EnvKey` literals once the registry is populated.\n *\n * Implementation: when `EnvKey` is `never`, the conditional resolves\n * to the user's `K`, accepting anything. Once typegen has populated\n * `KickEnv`, `EnvKey` becomes a real union and the conditional forces\n * `K` to be assignable to it.\n */\ntype ValueKey<K extends string> = [EnvKey] extends [never] ? K : K & EnvKey\n\n/**\n * Inject an environment variable value. Evaluated lazily so the env\n * is available at access time, not at decoration time.\n *\n * If no default is provided and the env var is missing, throws at access time\n * to catch misconfiguration early instead of returning undefined.\n *\n * Uses metadata + instance getter to work correctly with `useDefineForClassFields`.\n *\n * Type-safety:\n * - Without `kick typegen` run, any string key is accepted (back-compat).\n * - After typegen, `KickEnv` is populated and unknown keys become a tsc\n * error. The optional `defaultValue` is type-checked against the\n * schema's inferred type for that key.\n */\nexport function Value<K extends string>(\n envKey: ValueKey<K>,\n defaultValue?: K extends EnvKey ? KickEnv[K] : unknown,\n): PropertyDecorator {\n return (target, propertyKey) => {\n setInMetaMap(METADATA.VALUE, target, propertyKey as string, { envKey, defaultValue })\n }\n}\n\n// ── @Asset — typed asset path injection (assets-plan.md PR 3+) ─────────\n\nimport type { KickAssets } from './assets'\n\n/**\n * Flatten the nested `KickAssets` augmentation (typegen-emitted in\n * PR 4) into a string-literal union of dot/slash-joined paths.\n *\n * `interface KickAssets { mails: { welcome: () => string; orders: {\n * confirmation: () => string } } }` becomes\n * `'mails/welcome' | 'mails/orders/confirmation'`.\n *\n * Returns `never` when `KickAssets` is empty (no typegen has run yet)\n * so `AssetKeyArg` falls through to accept any string.\n */\ntype FlattenAssets<T, Prefix extends string = ''> = {\n [K in keyof T & string]: T[K] extends () => string\n ? `${Prefix}${K}`\n : T[K] extends Record<string, unknown>\n ? FlattenAssets<T[K], `${Prefix}${K}/`>\n : never\n}[keyof T & string]\n\n/** Flat union of every known `<namespace>/<key>` path. */\nexport type AssetKey = FlattenAssets<KickAssets>\n\n/**\n * Constraint mirroring `ValueKey<K>` — accepts any string when\n * `AssetKey` is `never` (back-compat for adopters who haven't run\n * `kick typegen` yet) but locks the argument to known literals once\n * the typegen-augmented `KickAssets` interface is populated.\n */\ntype AssetKeyArg<K extends string> = [AssetKey] extends [never] ? K : K & AssetKey\n\n/**\n * Inject the resolved file-system path for a typed asset. Mirrors\n * `@Value`'s lazy-getter pattern — the asset is resolved on every\n * property access, NOT at class instantiation, so:\n *\n * - Tests can swap fixtures + clear the cache without re-instantiating\n * the consuming class.\n * - The first access cost is paid once per process (the manifest cache\n * in `core/assets.ts` makes subsequent calls cheap).\n *\n * Type-safety:\n *\n * - Without typegen, any string key is accepted (back-compat — same\n * trick as `@Value`).\n * - After typegen, `KickAssets` is populated and `AssetKey` is a\n * union of every flattened `<namespace>/<key>` path. Unknown keys\n * become a TS error.\n *\n * @example\n * ```ts\n * import { Service, Asset } from '@forinda/kickjs'\n *\n * `@Service()`\n * class MailService {\n * `@Asset('mails/welcome')`\n * private welcomeTemplate!: string\n *\n * send(user: User) {\n * return ejs.renderFile(this.welcomeTemplate, { user })\n * }\n * }\n * ```\n */\nexport function Asset<K extends string>(assetKey: AssetKeyArg<K>): PropertyDecorator {\n return (target, propertyKey) => {\n setInMetaMap(METADATA.ASSET, target, propertyKey as string, { assetKey })\n }\n}\n\n// ── HTTP Route Decorators ───────────────────────────────────────────────\n\nexport interface RouteDefinition {\n method: string\n path: string\n handlerName: string\n validation?: {\n /** JSON Schema object for validating the request body */\n body?: any\n /** JSON Schema object for validating query parameters */\n query?: any\n /** JSON Schema object for validating URL params */\n params?: any\n /** Schema name in OpenAPI components/schemas for the request body. Auto-generated from handler name if omitted. */\n name?: string\n }\n}\n\nfunction createRouteDecorator(method: string) {\n return (path?: string, validation?: RouteDefinition['validation']): MethodDecorator => {\n return (target, propertyKey) => {\n pushClassMeta<RouteDefinition>(METADATA.ROUTES, target.constructor, {\n method,\n path: path || '/',\n handlerName: propertyKey as string,\n validation,\n })\n }\n }\n}\n\nexport const Get = createRouteDecorator('GET')\nexport const Post = createRouteDecorator('POST')\nexport const Put = createRouteDecorator('PUT')\nexport const Delete = createRouteDecorator('DELETE')\nexport const Patch = createRouteDecorator('PATCH')\n\n// ── Query Params Decorator ─────────────────────────────────────────────\n\nexport interface ApiQueryParamsConfig {\n /** Fields that can be used in filter queries (e.g., `?filter=status:eq:active`) */\n filterable?: string[]\n /** Fields that can be used in sort queries (e.g., `?sort=createdAt:desc`) */\n sortable?: string[]\n /** Fields that are searched with the `?q=` parameter */\n searchable?: string[]\n}\n\n/**\n * Column-object-based query params config (e.g., from DrizzleQueryParamsConfig).\n * `Object.keys()` is used to derive field names for OpenAPI docs.\n */\nexport interface ColumnApiQueryParamsConfig {\n columns: Record<string, any>\n sortable?: Record<string, any>\n searchColumns?: any[]\n [key: string]: any\n}\n\n/**\n * Normalize a query params config to the string-based ApiQueryParamsConfig.\n * Handles both string-based and column-object-based configs.\n */\nexport function normalizeApiQueryParamsConfig(\n config: ApiQueryParamsConfig | ColumnApiQueryParamsConfig,\n): ApiQueryParamsConfig {\n if ('columns' in config && config.columns && typeof config.columns === 'object') {\n return {\n filterable: Object.keys(config.columns),\n sortable: config.sortable ? Object.keys(config.sortable) : undefined,\n searchable: config.searchColumns\n ? config.searchColumns.map((col: any) => col?.name ?? '').filter(Boolean)\n : undefined,\n }\n }\n return config as ApiQueryParamsConfig\n}\n\n/**\n * Document the query parameters accepted by a GET endpoint.\n * Used by SwaggerAdapter to generate `filter`, `sort`, `page`, `limit`, and `q` params\n * in the OpenAPI spec, with descriptions listing the allowed fields.\n *\n * Accepts both string-based configs and column-object configs (e.g., DrizzleQueryParamsConfig).\n *\n * @example\n * ```ts\n * // String-based\n * @ApiQueryParams({\n * filterable: ['status', 'category', 'price'],\n * sortable: ['name', 'createdAt', 'price'],\n * searchable: ['name', 'description'],\n * })\n *\n * // Column-object-based (Drizzle)\n * @ApiQueryParams(TASK_QUERY_CONFIG)\n * ```\n */\nexport function ApiQueryParams(\n config: ApiQueryParamsConfig | ColumnApiQueryParamsConfig,\n): MethodDecorator {\n return (target, propertyKey) => {\n const normalized = normalizeApiQueryParamsConfig(config)\n setMethodMeta(METADATA.QUERY_PARAMS, normalized, target.constructor, propertyKey as string)\n }\n}\n\n// ── Middleware Decorators ───────────────────────────────────────────────\n\n/**\n * Middleware handler function.\n * Generic `TCtx` defaults to `any` — import `RequestContext` from\n * `@forinda/kickjs` for full type safety:\n *\n * ```ts\n * import type { MiddlewareHandler } from '@forinda/kickjs'\n * import type { RequestContext } from '@forinda/kickjs'\n *\n * const auth: MiddlewareHandler<RequestContext> = (ctx, next) => {\n * ctx.body // fully typed\n * next()\n * }\n * ```\n */\nexport type MiddlewareHandler<TCtx = any> = (ctx: TCtx, next: () => void) => void | Promise<void>\n\n/** Attach middleware handlers to a class or method */\nexport function Middleware(...handlers: MiddlewareHandler[]): ClassDecorator & MethodDecorator {\n return (target: any, propertyKey?: string | symbol) => {\n if (propertyKey) {\n pushMethodMeta(\n METADATA.METHOD_MIDDLEWARES,\n target.constructor,\n propertyKey as string,\n ...handlers,\n )\n } else {\n pushClassMeta(METADATA.CLASS_MIDDLEWARES, target, ...handlers)\n }\n }\n}\n\n// ── File Upload Decorator ───────────────────────────────────────────────\n\n/**\n * File filter — accepts short extensions ('jpg'), full MIME types ('image/jpeg'),\n * wildcards ('image/*'), or a function `(mimetype, filename) => boolean` for full control.\n */\nexport type FileTypeFilter = string[] | ((mimetype: string, filename: string) => boolean)\n\n/**\n * Shared upload options used by both the `@FileUpload` decorator and the\n * `upload.single()` / `upload.array()` / `upload.none()` middleware.\n */\nexport interface BaseUploadOptions {\n /** Max file size in bytes (default: 5MB) */\n maxSize?: number\n /**\n * Allowed file types:\n * - **string[]** — short extensions ('jpg'), full MIME types ('image/jpeg'), or wildcards ('image/*')\n * - **function** — `(mimetype, filename) => boolean` for full control\n */\n allowedTypes?: FileTypeFilter\n /** Extend the built-in extension-to-MIME map */\n customMimeMap?: Record<string, string>\n}\n\nexport interface FileUploadConfig extends BaseUploadOptions {\n mode: 'single' | 'array' | 'none'\n /** Form field name (default: 'file') */\n fieldName?: string\n /** Max files for array mode (default: 10) */\n maxCount?: number\n}\n\n/** Configure file upload handling for a controller method */\nexport function FileUpload(config: FileUploadConfig): MethodDecorator {\n return (target, propertyKey) => {\n setMethodMeta(METADATA.FILE_UPLOAD, config, target.constructor, propertyKey as string)\n }\n}\n\n// ── Builder Decorator ───────────────────────────────────────────────────\n\n/** Add a static builder() method for fluent construction */\nexport function Builder(target: any): void {\n setClassMeta(METADATA.BUILDER, true, target)\n\n target.builder = function () {\n const props: Record<string, any> = {}\n const proxy: any = new Proxy(\n {},\n {\n get(_, key) {\n if (key === 'build') {\n return () => Object.assign(new target(), props)\n }\n return (value: any) => {\n props[key as string] = value\n return proxy\n }\n },\n },\n )\n return proxy\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAuBA,MAAM,uBAA8C,EAAE;AAGtD,M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
|
*
|
|
@@ -199,10 +199,12 @@ var Logger = class Logger {
|
|
|
199
199
|
this.provider.debug(msg, ...args);
|
|
200
200
|
}
|
|
201
201
|
trace(msg, ...args) {
|
|
202
|
-
|
|
202
|
+
if (this.provider.trace) this.provider.trace(msg, ...args);
|
|
203
|
+
else this.provider.debug(msg, ...args);
|
|
203
204
|
}
|
|
204
205
|
fatal(msg, ...args) {
|
|
205
|
-
|
|
206
|
+
if (this.provider.fatal) this.provider.fatal(msg, ...args);
|
|
207
|
+
else this.provider.error(msg, ...args);
|
|
206
208
|
}
|
|
207
209
|
};
|
|
208
210
|
/** Shorthand for Logger.for(name) */
|
package/dist/core/logger.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.mjs","names":[],"sources":["../../src/core/logger.ts"],"sourcesContent":["import pino from 'pino'\n\nconst isDev = process.env.NODE_ENV !== 'production'\n\n/** Root pino logger instance */\nexport const rootLogger = pino({\n level: process.env.LOG_LEVEL || 'info',\n ...(isDev\n ? {\n transport: {\n target: 'pino-pretty',\n options: {\n colorize: true,\n translateTime: 'SYS:HH:MM:ss.l',\n singleLine: true,\n ignore: 'pid,hostname,component',\n messageFormat: '{if component}[{component}] {end}{msg}',\n },\n },\n }\n : {}),\n})\n\n// ── LoggerProvider interface ───────────────────────────────────────────\n\n/**\n * Pluggable logger backend.\n *\n * Implement this interface to replace the default pino-based logging\n * with any logging library (winston, bunyan, console, etc.).\n */\nexport interface LoggerProvider {\n info(msg: string, ...args: any[]): void\n warn(msg: string, ...args: any[]): void\n error(msg: string, ...args: any[]): void\n debug(msg: string, ...args: any[]): void\n trace?(msg: string, ...args: any[]): void\n fatal?(msg: string, ...args: any[]): void\n /** Return a child provider scoped to the given component name */\n child(bindings: { component: string }): LoggerProvider\n}\n\n// ── PinoLoggerProvider (default) ───────────────────────────────────────\n\n/** Default provider that delegates to the root pino instance */\nclass PinoLoggerProvider implements LoggerProvider {\n private log: pino.Logger\n\n constructor(pinoInstance?: pino.Logger) {\n this.log = pinoInstance ?? rootLogger\n }\n\n info(msg: string, ...args: any[]) {\n this.log.info(msg, ...args)\n }\n warn(msg: string, ...args: any[]) {\n this.log.warn(msg, ...args)\n }\n error(msg: string, ...args: any[]) {\n this.log.error(msg, ...args)\n }\n debug(msg: string, ...args: any[]) {\n this.log.debug(msg, ...args)\n }\n trace(msg: string, ...args: any[]) {\n this.log.trace(msg, ...args)\n }\n fatal(msg: string, ...args: any[]) {\n this.log.fatal(msg, ...args)\n }\n child(bindings: { component: string }): LoggerProvider {\n return new PinoLoggerProvider(this.log.child(bindings))\n }\n}\n\n// ── ConsoleLoggerProvider ──────────────────────────────────────────────\n\n/**\n * Built-in fallback provider that uses `console.*` methods.\n * Useful for environments where pino is unavailable or undesired.\n */\nexport class ConsoleLoggerProvider implements LoggerProvider {\n private prefix: string\n\n constructor(prefix?: string) {\n this.prefix = prefix ?? ''\n }\n\n private fmt(msg: string): string {\n return this.prefix ? `[${this.prefix}] ${msg}` : msg\n }\n\n info(msg: string, ...args: any[]) {\n console.log(this.fmt(msg), ...args)\n }\n warn(msg: string, ...args: any[]) {\n console.warn(this.fmt(msg), ...args)\n }\n error(msg: string, ...args: any[]) {\n console.error(this.fmt(msg), ...args)\n }\n debug(msg: string, ...args: any[]) {\n console.debug(this.fmt(msg), ...args)\n }\n trace(msg: string, ...args: any[]) {\n console.trace(this.fmt(msg), ...args)\n }\n fatal(msg: string, ...args: any[]) {\n console.error(this.fmt(msg), ...args)\n }\n child(bindings: { component: string }): LoggerProvider {\n return new ConsoleLoggerProvider(bindings.component)\n }\n}\n\n// ── Active provider ────────────────────────────────────────────────────\n\nlet activeProvider: LoggerProvider = new PinoLoggerProvider()\n\n/** Cache of named loggers to avoid creating duplicates */\nconst loggerCache = new Map<string, Logger>()\n\n/**\n * Named logger with component context.\n *\n * @example\n * ```ts\n * // Static factory — preferred\n * const log = Logger.for('UserService')\n * log.info('User created')\n * // Output: [UserService] User created\n *\n * // Shorthand function\n * const log = createLogger('OrderService')\n *\n * // Pluggable backend\n * Logger.setProvider(new ConsoleLoggerProvider())\n *\n * // Injectable — auto-named from class\n * class MyService {\n * @Autowired() private logger!: Logger\n * // or inject a named one:\n * private log = Logger.for('MyService')\n * }\n * ```\n */\nexport class Logger {\n private _provider: LoggerProvider\n private _providerVersion: number\n private _name?: string\n\n /**\n * Optional context provider for request-scoped log enrichment.\n * Set by the HTTP package to inject requestId from AsyncLocalStorage.\n * Returns extra fields to merge into every log call, or null if outside a request.\n */\n static _contextProvider: (() => Record<string, any> | null) | null = null\n\n /** Incremented on every setProvider/resetProvider so instances know to refresh */\n private static _providerVersion = 0\n\n constructor(name?: string) {\n this._name = name\n this._providerVersion = Logger._providerVersion\n this._provider = name ? activeProvider.child({ component: name }) : activeProvider\n }\n\n /** Re-derive the provider if setProvider() was called since construction/last access */\n private get provider(): LoggerProvider {\n if (this._providerVersion !== Logger._providerVersion) {\n this._providerVersion = Logger._providerVersion\n this._provider = this._name ? activeProvider.child({ component: this._name }) : activeProvider\n }\n return this._provider\n }\n\n /**\n * Replace the logging backend for **all** Logger instances created after\n * this call. Clears the logger cache so subsequent `Logger.for()` calls\n * pick up the new provider.\n *\n * @example\n * ```ts\n * Logger.setProvider(new ConsoleLoggerProvider())\n * ```\n */\n static setProvider(provider: LoggerProvider): void {\n activeProvider = provider\n Logger._providerVersion++\n loggerCache.clear()\n }\n\n /** Return the currently active provider (useful for testing) */\n static getProvider(): LoggerProvider {\n return activeProvider\n }\n\n /**\n * Reset the provider back to the default pino-based implementation.\n * Primarily intended for test teardown.\n */\n static resetProvider(): void {\n activeProvider = new PinoLoggerProvider()\n Logger._providerVersion++\n loggerCache.clear()\n }\n\n /** Create or retrieve a cached named logger */\n static for(name: string): Logger {\n let cached = loggerCache.get(name)\n if (!cached) {\n cached = new Logger(name)\n loggerCache.set(name, cached)\n }\n return cached\n }\n\n /** Create a child logger with a sub-component name */\n child(name: string): Logger {\n return new Logger(name)\n }\n\n /** Get request context (requestId, etc.) if inside a request */\n private ctx(): Record<string, any> | undefined {\n return Logger._contextProvider?.() ?? undefined\n }\n\n info(msg: string, ...args: any[]) {\n this.provider.info(msg, ...args)\n }\n\n warn(msg: string, ...args: any[]) {\n this.provider.warn(msg, ...args)\n }\n\n error(msgOrObj: any, msg?: string, ...args: any[]) {\n if (typeof msgOrObj === 'string') {\n this.provider.error(msgOrObj)\n } else if (msg) {\n this.provider.error(msg, ...args)\n } else {\n this.provider.error(String(msgOrObj))\n }\n }\n\n debug(msg: string, ...args: any[]) {\n this.provider.debug(msg, ...args)\n }\n\n trace(msg: string, ...args: any[]) {\n this.provider.trace ? this.provider.trace(msg, ...args) : this.provider.debug(msg, ...args)\n }\n\n fatal(msg: string, ...args: any[]) {\n this.provider.fatal ? this.provider.fatal(msg, ...args) : this.provider.error(msg, ...args)\n }\n}\n\n/** Shorthand for Logger.for(name) */\nexport function createLogger(name: string): Logger {\n return Logger.for(name)\n}\n"],"mappings":";;;;;;;;;;;;AAEA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAGvC,MAAa,aAAa,KAAK;CAC7B,OAAO,QAAQ,IAAI,aAAa;CAChC,GAAI,QACA,EACE,WAAW;EACT,QAAQ;EACR,SAAS;GACP,UAAU;GACV,eAAe;GACf,YAAY;GACZ,QAAQ;GACR,eAAe;GAChB;EACF,EACF,GACD,EAAE;CACP,CAAC;;AAwBF,IAAM,qBAAN,MAAM,mBAA6C;CACjD;CAEA,YAAY,cAA4B;AACtC,OAAK,MAAM,gBAAgB;;CAG7B,KAAK,KAAa,GAAG,MAAa;AAChC,OAAK,IAAI,KAAK,KAAK,GAAG,KAAK;;CAE7B,KAAK,KAAa,GAAG,MAAa;AAChC,OAAK,IAAI,KAAK,KAAK,GAAG,KAAK;;CAE7B,MAAM,KAAa,GAAG,MAAa;AACjC,OAAK,IAAI,MAAM,KAAK,GAAG,KAAK;;CAE9B,MAAM,KAAa,GAAG,MAAa;AACjC,OAAK,IAAI,MAAM,KAAK,GAAG,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AM,KAAK,GAAG,KAAK,GAAG,KAAK,SAAS,MAAM,KAAK,GAAG,KAAK;;CAG7F,MAAM,KAAa,GAAG,MAAa;AACjC,OAAK,SAAS,QAAQ,KAAK,SAAS,MAAM,KAAK,GAAG,KAAK,GAAG,KAAK,SAAS,MAAM,KAAK,GAAG,KAAK;;;;AAK/F,SAAgB,aAAa,MAAsB;AACjD,QAAO,OAAO,IAAI,KAAK"}
|
|
1
|
+
{"version":3,"file":"logger.mjs","names":[],"sources":["../../src/core/logger.ts"],"sourcesContent":["import pino from 'pino'\n\nconst isDev = process.env.NODE_ENV !== 'production'\n\n/** Root pino logger instance */\nexport const rootLogger = pino({\n level: process.env.LOG_LEVEL || 'info',\n ...(isDev\n ? {\n transport: {\n target: 'pino-pretty',\n options: {\n colorize: true,\n translateTime: 'SYS:HH:MM:ss.l',\n singleLine: true,\n ignore: 'pid,hostname,component',\n messageFormat: '{if component}[{component}] {end}{msg}',\n },\n },\n }\n : {}),\n})\n\n// ── LoggerProvider interface ───────────────────────────────────────────\n\n/**\n * Pluggable logger backend.\n *\n * Implement this interface to replace the default pino-based logging\n * with any logging library (winston, bunyan, console, etc.).\n */\nexport interface LoggerProvider {\n info(msg: string, ...args: any[]): void\n warn(msg: string, ...args: any[]): void\n error(msg: string, ...args: any[]): void\n debug(msg: string, ...args: any[]): void\n trace?(msg: string, ...args: any[]): void\n fatal?(msg: string, ...args: any[]): void\n /** Return a child provider scoped to the given component name */\n child(bindings: { component: string }): LoggerProvider\n}\n\n// ── PinoLoggerProvider (default) ───────────────────────────────────────\n\n/** Default provider that delegates to the root pino instance */\nclass PinoLoggerProvider implements LoggerProvider {\n private log: pino.Logger\n\n constructor(pinoInstance?: pino.Logger) {\n this.log = pinoInstance ?? rootLogger\n }\n\n info(msg: string, ...args: any[]) {\n this.log.info(msg, ...args)\n }\n warn(msg: string, ...args: any[]) {\n this.log.warn(msg, ...args)\n }\n error(msg: string, ...args: any[]) {\n this.log.error(msg, ...args)\n }\n debug(msg: string, ...args: any[]) {\n this.log.debug(msg, ...args)\n }\n trace(msg: string, ...args: any[]) {\n this.log.trace(msg, ...args)\n }\n fatal(msg: string, ...args: any[]) {\n this.log.fatal(msg, ...args)\n }\n child(bindings: { component: string }): LoggerProvider {\n return new PinoLoggerProvider(this.log.child(bindings))\n }\n}\n\n// ── ConsoleLoggerProvider ──────────────────────────────────────────────\n\n/**\n * Built-in fallback provider that uses `console.*` methods.\n * Useful for environments where pino is unavailable or undesired.\n */\nexport class ConsoleLoggerProvider implements LoggerProvider {\n private prefix: string\n\n constructor(prefix?: string) {\n this.prefix = prefix ?? ''\n }\n\n private fmt(msg: string): string {\n return this.prefix ? `[${this.prefix}] ${msg}` : msg\n }\n\n info(msg: string, ...args: any[]) {\n console.log(this.fmt(msg), ...args)\n }\n warn(msg: string, ...args: any[]) {\n console.warn(this.fmt(msg), ...args)\n }\n error(msg: string, ...args: any[]) {\n console.error(this.fmt(msg), ...args)\n }\n debug(msg: string, ...args: any[]) {\n console.debug(this.fmt(msg), ...args)\n }\n trace(msg: string, ...args: any[]) {\n console.trace(this.fmt(msg), ...args)\n }\n fatal(msg: string, ...args: any[]) {\n console.error(this.fmt(msg), ...args)\n }\n child(bindings: { component: string }): LoggerProvider {\n return new ConsoleLoggerProvider(bindings.component)\n }\n}\n\n// ── Active provider ────────────────────────────────────────────────────\n\nlet activeProvider: LoggerProvider = new PinoLoggerProvider()\n\n/** Cache of named loggers to avoid creating duplicates */\nconst loggerCache = new Map<string, Logger>()\n\n/**\n * Named logger with component context.\n *\n * @example\n * ```ts\n * // Static factory — preferred\n * const log = Logger.for('UserService')\n * log.info('User created')\n * // Output: [UserService] User created\n *\n * // Shorthand function\n * const log = createLogger('OrderService')\n *\n * // Pluggable backend\n * Logger.setProvider(new ConsoleLoggerProvider())\n *\n * // Injectable — auto-named from class\n * class MyService {\n * @Autowired() private logger!: Logger\n * // or inject a named one:\n * private log = Logger.for('MyService')\n * }\n * ```\n */\nexport class Logger {\n private _provider: LoggerProvider\n private _providerVersion: number\n private _name?: string\n\n /**\n * Optional context provider for request-scoped log enrichment.\n * Set by the HTTP package to inject requestId from AsyncLocalStorage.\n * Returns extra fields to merge into every log call, or null if outside a request.\n */\n static _contextProvider: (() => Record<string, any> | null) | null = null\n\n /** Incremented on every setProvider/resetProvider so instances know to refresh */\n private static _providerVersion = 0\n\n constructor(name?: string) {\n this._name = name\n this._providerVersion = Logger._providerVersion\n this._provider = name ? activeProvider.child({ component: name }) : activeProvider\n }\n\n /** Re-derive the provider if setProvider() was called since construction/last access */\n private get provider(): LoggerProvider {\n if (this._providerVersion !== Logger._providerVersion) {\n this._providerVersion = Logger._providerVersion\n this._provider = this._name ? activeProvider.child({ component: this._name }) : activeProvider\n }\n return this._provider\n }\n\n /**\n * Replace the logging backend for **all** Logger instances created after\n * this call. Clears the logger cache so subsequent `Logger.for()` calls\n * pick up the new provider.\n *\n * @example\n * ```ts\n * Logger.setProvider(new ConsoleLoggerProvider())\n * ```\n */\n static setProvider(provider: LoggerProvider): void {\n activeProvider = provider\n Logger._providerVersion++\n loggerCache.clear()\n }\n\n /** Return the currently active provider (useful for testing) */\n static getProvider(): LoggerProvider {\n return activeProvider\n }\n\n /**\n * Reset the provider back to the default pino-based implementation.\n * Primarily intended for test teardown.\n */\n static resetProvider(): void {\n activeProvider = new PinoLoggerProvider()\n Logger._providerVersion++\n loggerCache.clear()\n }\n\n /** Create or retrieve a cached named logger */\n static for(name: string): Logger {\n let cached = loggerCache.get(name)\n if (!cached) {\n cached = new Logger(name)\n loggerCache.set(name, cached)\n }\n return cached\n }\n\n /** Create a child logger with a sub-component name */\n child(name: string): Logger {\n return new Logger(name)\n }\n\n /** Get request context (requestId, etc.) if inside a request */\n private ctx(): Record<string, any> | undefined {\n return Logger._contextProvider?.() ?? undefined\n }\n\n info(msg: string, ...args: any[]) {\n this.provider.info(msg, ...args)\n }\n\n warn(msg: string, ...args: any[]) {\n this.provider.warn(msg, ...args)\n }\n\n error(msgOrObj: any, msg?: string, ...args: any[]) {\n if (typeof msgOrObj === 'string') {\n this.provider.error(msgOrObj)\n } else if (msg) {\n this.provider.error(msg, ...args)\n } else {\n this.provider.error(String(msgOrObj))\n }\n }\n\n debug(msg: string, ...args: any[]) {\n this.provider.debug(msg, ...args)\n }\n\n trace(msg: string, ...args: any[]) {\n if (this.provider.trace) this.provider.trace(msg, ...args)\n else this.provider.debug(msg, ...args)\n }\n\n fatal(msg: string, ...args: any[]) {\n if (this.provider.fatal) this.provider.fatal(msg, ...args)\n else this.provider.error(msg, ...args)\n }\n}\n\n/** Shorthand for Logger.for(name) */\nexport function createLogger(name: string): Logger {\n return Logger.for(name)\n}\n"],"mappings":";;;;;;;;;;;;AAEA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAGvC,MAAa,aAAa,KAAK;CAC7B,OAAO,QAAQ,IAAI,aAAa;CAChC,GAAI,QACA,EACE,WAAW;EACT,QAAQ;EACR,SAAS;GACP,UAAU;GACV,eAAe;GACf,YAAY;GACZ,QAAQ;GACR,eAAe;GAChB;EACF,EACF,GACD,EAAE;CACP,CAAC;;AAwBF,IAAM,qBAAN,MAAM,mBAA6C;CACjD;CAEA,YAAY,cAA4B;AACtC,OAAK,MAAM,gBAAgB;;CAG7B,KAAK,KAAa,GAAG,MAAa;AAChC,OAAK,IAAI,KAAK,KAAK,GAAG,KAAK;;CAE7B,KAAK,KAAa,GAAG,MAAa;AAChC,OAAK,IAAI,KAAK,KAAK,GAAG,KAAK;;CAE7B,MAAM,KAAa,GAAG,MAAa;AACjC,OAAK,IAAI,MAAM,KAAK,GAAG,KAAK;;CAE9B,MAAM,KAAa,GAAG,MAAa;AACjC,OAAK,IAAI,MAAM,KAAK,GAAG,KAAK;;CAE9B,MAAM,KAAa,GAAG,MAAa;AACjC,OAAK,IAAI,MAAM,KAAK,GAAG,KAAK;;CAE9B,MAAM,KAAa,GAAG,MAAa;AACjC,OAAK,IAAI,MAAM,KAAK,GAAG,KAAK;;CAE9B,MAAM,UAAiD;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