@buenojs/bueno 0.8.3 → 0.8.5
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/README.md +136 -16
- package/dist/cli/{index.js → bin.js} +3036 -1421
- package/dist/container/index.js +250 -0
- package/dist/context/index.js +219 -0
- package/dist/database/index.js +493 -0
- package/dist/frontend/index.js +7697 -0
- package/dist/health/index.js +364 -0
- package/dist/i18n/index.js +345 -0
- package/dist/index.js +11043 -6482
- package/dist/jobs/index.js +819 -0
- package/dist/lock/index.js +367 -0
- package/dist/logger/index.js +281 -0
- package/dist/metrics/index.js +289 -0
- package/dist/middleware/index.js +77 -0
- package/dist/migrations/index.js +571 -0
- package/dist/modules/index.js +3346 -0
- package/dist/notification/index.js +484 -0
- package/dist/observability/index.js +331 -0
- package/dist/openapi/index.js +776 -0
- package/dist/orm/index.js +1356 -0
- package/dist/router/index.js +886 -0
- package/dist/rpc/index.js +691 -0
- package/dist/schema/index.js +400 -0
- package/dist/telemetry/index.js +595 -0
- package/dist/template/index.js +640 -0
- package/dist/templates/index.js +640 -0
- package/dist/testing/index.js +1111 -0
- package/dist/types/index.js +60 -0
- package/package.json +121 -27
- package/src/cache/index.ts +2 -1
- package/src/cli/bin.ts +2 -2
- package/src/cli/commands/build.ts +183 -165
- package/src/cli/commands/dev.ts +96 -89
- package/src/cli/commands/generate.ts +142 -111
- package/src/cli/commands/help.ts +20 -16
- package/src/cli/commands/index.ts +3 -6
- package/src/cli/commands/migration.ts +124 -105
- package/src/cli/commands/new.ts +392 -438
- package/src/cli/commands/start.ts +81 -79
- package/src/cli/core/args.ts +68 -50
- package/src/cli/core/console.ts +89 -95
- package/src/cli/core/index.ts +4 -4
- package/src/cli/core/prompt.ts +65 -62
- package/src/cli/core/spinner.ts +23 -20
- package/src/cli/index.ts +46 -38
- package/src/cli/templates/database/index.ts +61 -0
- package/src/cli/templates/database/mysql.ts +14 -0
- package/src/cli/templates/database/none.ts +16 -0
- package/src/cli/templates/database/postgresql.ts +14 -0
- package/src/cli/templates/database/sqlite.ts +14 -0
- package/src/cli/templates/deploy.ts +29 -26
- package/src/cli/templates/docker.ts +41 -30
- package/src/cli/templates/frontend/index.ts +63 -0
- package/src/cli/templates/frontend/none.ts +17 -0
- package/src/cli/templates/frontend/react.ts +140 -0
- package/src/cli/templates/frontend/solid.ts +134 -0
- package/src/cli/templates/frontend/svelte.ts +131 -0
- package/src/cli/templates/frontend/vue.ts +130 -0
- package/src/cli/templates/generators/index.ts +339 -0
- package/src/cli/templates/generators/types.ts +56 -0
- package/src/cli/templates/index.ts +35 -2
- package/src/cli/templates/project/api.ts +81 -0
- package/src/cli/templates/project/default.ts +140 -0
- package/src/cli/templates/project/fullstack.ts +111 -0
- package/src/cli/templates/project/index.ts +95 -0
- package/src/cli/templates/project/minimal.ts +45 -0
- package/src/cli/templates/project/types.ts +94 -0
- package/src/cli/templates/project/website.ts +263 -0
- package/src/cli/utils/fs.ts +55 -41
- package/src/cli/utils/index.ts +3 -2
- package/src/cli/utils/strings.ts +47 -33
- package/src/cli/utils/version.ts +47 -0
- package/src/config/env-validation.ts +100 -0
- package/src/config/env.ts +169 -41
- package/src/config/index.ts +28 -20
- package/src/config/loader.ts +25 -16
- package/src/config/merge.ts +21 -10
- package/src/config/types.ts +545 -25
- package/src/config/validation.ts +215 -7
- package/src/container/forward-ref.ts +22 -22
- package/src/container/index.ts +34 -12
- package/src/context/index.ts +11 -1
- package/src/database/index.ts +7 -190
- package/src/database/orm/builder.ts +457 -0
- package/src/database/orm/casts/index.ts +130 -0
- package/src/database/orm/casts/types.ts +25 -0
- package/src/database/orm/compiler.ts +304 -0
- package/src/database/orm/hooks/index.ts +114 -0
- package/src/database/orm/index.ts +61 -0
- package/src/database/orm/model-registry.ts +59 -0
- package/src/database/orm/model.ts +821 -0
- package/src/database/orm/relationships/base.ts +146 -0
- package/src/database/orm/relationships/belongs-to-many.ts +179 -0
- package/src/database/orm/relationships/belongs-to.ts +56 -0
- package/src/database/orm/relationships/has-many.ts +45 -0
- package/src/database/orm/relationships/has-one.ts +41 -0
- package/src/database/orm/relationships/index.ts +11 -0
- package/src/database/orm/scopes/index.ts +55 -0
- package/src/events/__tests__/event-system.test.ts +235 -0
- package/src/events/config.ts +238 -0
- package/src/events/example-usage.ts +185 -0
- package/src/events/index.ts +278 -0
- package/src/events/manager.ts +385 -0
- package/src/events/registry.ts +182 -0
- package/src/events/types.ts +124 -0
- package/src/frontend/api-routes.ts +65 -23
- package/src/frontend/bundler.ts +76 -34
- package/src/frontend/console-client.ts +2 -2
- package/src/frontend/console-stream.ts +94 -38
- package/src/frontend/dev-server.ts +94 -46
- package/src/frontend/file-router.ts +61 -19
- package/src/frontend/frameworks/index.ts +37 -10
- package/src/frontend/frameworks/react.ts +10 -8
- package/src/frontend/frameworks/solid.ts +11 -9
- package/src/frontend/frameworks/svelte.ts +15 -9
- package/src/frontend/frameworks/vue.ts +13 -11
- package/src/frontend/hmr-client.ts +12 -10
- package/src/frontend/hmr.ts +146 -103
- package/src/frontend/index.ts +14 -5
- package/src/frontend/islands.ts +41 -22
- package/src/frontend/isr.ts +59 -37
- package/src/frontend/layout.ts +36 -21
- package/src/frontend/ssr/react.ts +74 -27
- package/src/frontend/ssr/solid.ts +54 -20
- package/src/frontend/ssr/svelte.ts +48 -14
- package/src/frontend/ssr/vue.ts +50 -18
- package/src/frontend/ssr.ts +83 -39
- package/src/frontend/types.ts +91 -56
- package/src/health/index.ts +21 -9
- package/src/i18n/engine.ts +305 -0
- package/src/i18n/index.ts +38 -0
- package/src/i18n/loader.ts +218 -0
- package/src/i18n/middleware.ts +164 -0
- package/src/i18n/negotiator.ts +162 -0
- package/src/i18n/types.ts +158 -0
- package/src/index.ts +179 -27
- package/src/jobs/drivers/memory.ts +315 -0
- package/src/jobs/drivers/redis.ts +459 -0
- package/src/jobs/index.ts +30 -0
- package/src/jobs/queue.ts +281 -0
- package/src/jobs/types.ts +295 -0
- package/src/jobs/worker.ts +380 -0
- package/src/logger/index.ts +1 -3
- package/src/logger/transports/index.ts +62 -22
- package/src/metrics/index.ts +25 -16
- package/src/migrations/index.ts +9 -0
- package/src/modules/filters.ts +13 -17
- package/src/modules/guards.ts +49 -26
- package/src/modules/index.ts +409 -298
- package/src/modules/interceptors.ts +58 -20
- package/src/modules/lazy.ts +11 -19
- package/src/modules/lifecycle.ts +15 -7
- package/src/modules/metadata.ts +15 -5
- package/src/modules/pipes.ts +94 -72
- package/src/notification/channels/base.ts +68 -0
- package/src/notification/channels/email.ts +105 -0
- package/src/notification/channels/push.ts +104 -0
- package/src/notification/channels/sms.ts +105 -0
- package/src/notification/channels/whatsapp.ts +104 -0
- package/src/notification/index.ts +48 -0
- package/src/notification/service.ts +354 -0
- package/src/notification/types.ts +344 -0
- package/src/observability/__tests__/observability.test.ts +483 -0
- package/src/observability/breadcrumbs.ts +114 -0
- package/src/observability/index.ts +136 -0
- package/src/observability/interceptor.ts +85 -0
- package/src/observability/service.ts +303 -0
- package/src/observability/trace.ts +37 -0
- package/src/observability/types.ts +196 -0
- package/src/openapi/__tests__/decorators.test.ts +335 -0
- package/src/openapi/__tests__/document-builder.test.ts +285 -0
- package/src/openapi/__tests__/route-scanner.test.ts +334 -0
- package/src/openapi/__tests__/schema-generator.test.ts +275 -0
- package/src/openapi/decorators.ts +328 -0
- package/src/openapi/document-builder.ts +274 -0
- package/src/openapi/index.ts +112 -0
- package/src/openapi/metadata.ts +112 -0
- package/src/openapi/route-scanner.ts +289 -0
- package/src/openapi/schema-generator.ts +256 -0
- package/src/openapi/swagger-module.ts +166 -0
- package/src/openapi/types.ts +398 -0
- package/src/orm/index.ts +10 -0
- package/src/rpc/index.ts +3 -1
- package/src/schema/index.ts +9 -0
- package/src/security/index.ts +15 -6
- package/src/ssg/index.ts +9 -8
- package/src/telemetry/index.ts +76 -22
- package/src/template/index.ts +7 -0
- package/src/templates/engine.ts +224 -0
- package/src/templates/index.ts +9 -0
- package/src/templates/loader.ts +331 -0
- package/src/templates/renderers/markdown.ts +212 -0
- package/src/templates/renderers/simple.ts +269 -0
- package/src/templates/types.ts +154 -0
- package/src/testing/index.ts +100 -27
- package/src/types/optional-deps.d.ts +347 -187
- package/src/validation/index.ts +92 -2
- package/src/validation/schemas.ts +536 -0
- package/tests/integration/fullstack.test.ts +4 -4
- package/tests/unit/database.test.ts +2 -72
- package/tests/unit/env-validation.test.ts +166 -0
- package/tests/unit/events.test.ts +910 -0
- package/tests/unit/i18n.test.ts +455 -0
- package/tests/unit/jobs.test.ts +493 -0
- package/tests/unit/notification.test.ts +988 -0
- package/tests/unit/observability.test.ts +453 -0
- package/tests/unit/orm/builder.test.ts +323 -0
- package/tests/unit/orm/casts.test.ts +179 -0
- package/tests/unit/orm/compiler.test.ts +220 -0
- package/tests/unit/orm/eager-loading.test.ts +285 -0
- package/tests/unit/orm/hooks.test.ts +191 -0
- package/tests/unit/orm/model.test.ts +373 -0
- package/tests/unit/orm/relationships.test.ts +303 -0
- package/tests/unit/orm/scopes.test.ts +74 -0
- package/tests/unit/templates-simple.test.ts +53 -0
- package/tests/unit/templates.test.ts +454 -0
- package/tests/unit/validation.test.ts +18 -24
- package/tsconfig.json +11 -3
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
* - Add headers or modify request/response
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import type { Context } from "../context";
|
|
20
19
|
import type { Token } from "../container";
|
|
20
|
+
import type { Context } from "../context";
|
|
21
21
|
|
|
22
22
|
// ============= Types =============
|
|
23
23
|
|
|
@@ -72,7 +72,7 @@ export interface NestInterceptor<T = unknown, R = unknown> {
|
|
|
72
72
|
*/
|
|
73
73
|
export type InterceptorFn = (
|
|
74
74
|
context: Context,
|
|
75
|
-
next: () => Promise<unknown
|
|
75
|
+
next: () => Promise<unknown>,
|
|
76
76
|
) => Promise<unknown> | unknown;
|
|
77
77
|
|
|
78
78
|
/**
|
|
@@ -81,7 +81,10 @@ export type InterceptorFn = (
|
|
|
81
81
|
* - An interceptor class instance
|
|
82
82
|
* - An interceptor function
|
|
83
83
|
*/
|
|
84
|
-
export type Interceptor =
|
|
84
|
+
export type Interceptor =
|
|
85
|
+
| Token<NestInterceptor>
|
|
86
|
+
| NestInterceptor
|
|
87
|
+
| InterceptorFn;
|
|
85
88
|
|
|
86
89
|
// ============= Metadata Storage =============
|
|
87
90
|
|
|
@@ -92,19 +95,27 @@ type Constructor = new (...args: unknown[]) => unknown;
|
|
|
92
95
|
const interceptorsClassMetadata = new WeakMap<Constructor, Interceptor[]>();
|
|
93
96
|
|
|
94
97
|
// WeakMap for storing interceptors metadata on method prototypes
|
|
95
|
-
const interceptorsMethodMetadata = new WeakMap<
|
|
98
|
+
const interceptorsMethodMetadata = new WeakMap<
|
|
99
|
+
object,
|
|
100
|
+
Map<string | symbol, Interceptor[]>
|
|
101
|
+
>();
|
|
96
102
|
|
|
97
103
|
/**
|
|
98
104
|
* Set interceptors on a class constructor
|
|
99
105
|
*/
|
|
100
|
-
function setClassInterceptors(
|
|
106
|
+
function setClassInterceptors(
|
|
107
|
+
target: Constructor,
|
|
108
|
+
interceptors: Interceptor[],
|
|
109
|
+
): void {
|
|
101
110
|
interceptorsClassMetadata.set(target, interceptors);
|
|
102
111
|
}
|
|
103
112
|
|
|
104
113
|
/**
|
|
105
114
|
* Get interceptors from a class constructor
|
|
106
115
|
*/
|
|
107
|
-
export function getClassInterceptors(
|
|
116
|
+
export function getClassInterceptors(
|
|
117
|
+
target: Constructor,
|
|
118
|
+
): Interceptor[] | undefined {
|
|
108
119
|
return interceptorsClassMetadata.get(target);
|
|
109
120
|
}
|
|
110
121
|
|
|
@@ -153,7 +164,9 @@ export function getMethodInterceptors(
|
|
|
153
164
|
* }
|
|
154
165
|
* ```
|
|
155
166
|
*/
|
|
156
|
-
export function UseInterceptors(
|
|
167
|
+
export function UseInterceptors(
|
|
168
|
+
...interceptors: Interceptor[]
|
|
169
|
+
): MethodDecorator & ClassDecorator {
|
|
157
170
|
const decorator = (
|
|
158
171
|
target: unknown,
|
|
159
172
|
propertyKey?: string | symbol,
|
|
@@ -162,14 +175,21 @@ export function UseInterceptors(...interceptors: Interceptor[]): MethodDecorator
|
|
|
162
175
|
if (propertyKey !== undefined && descriptor !== undefined) {
|
|
163
176
|
// Method decorator
|
|
164
177
|
const targetObj = target as object;
|
|
165
|
-
const existingInterceptors =
|
|
166
|
-
|
|
178
|
+
const existingInterceptors =
|
|
179
|
+
getMethodInterceptors(targetObj, propertyKey) ?? [];
|
|
180
|
+
setMethodInterceptors(targetObj, propertyKey, [
|
|
181
|
+
...existingInterceptors,
|
|
182
|
+
...interceptors,
|
|
183
|
+
]);
|
|
167
184
|
return descriptor;
|
|
168
185
|
} else {
|
|
169
186
|
// Class decorator
|
|
170
187
|
const targetClass = target as Constructor;
|
|
171
188
|
const existingInterceptors = getClassInterceptors(targetClass) ?? [];
|
|
172
|
-
setClassInterceptors(targetClass, [
|
|
189
|
+
setClassInterceptors(targetClass, [
|
|
190
|
+
...existingInterceptors,
|
|
191
|
+
...interceptors,
|
|
192
|
+
]);
|
|
173
193
|
}
|
|
174
194
|
};
|
|
175
195
|
return decorator as MethodDecorator & ClassDecorator;
|
|
@@ -235,8 +255,13 @@ export interface TransformResponse<T> {
|
|
|
235
255
|
* // Response: { data: [{ id: 1, name: 'John' }], timestamp: '2024-01-15T10:30:00.000Z' }
|
|
236
256
|
* ```
|
|
237
257
|
*/
|
|
238
|
-
export class TransformInterceptor<T = unknown>
|
|
239
|
-
|
|
258
|
+
export class TransformInterceptor<T = unknown>
|
|
259
|
+
implements NestInterceptor<T, TransformResponse<T>>
|
|
260
|
+
{
|
|
261
|
+
async intercept(
|
|
262
|
+
context: Context,
|
|
263
|
+
next: CallHandler<T>,
|
|
264
|
+
): Promise<TransformResponse<T>> {
|
|
240
265
|
const result = await next.handle();
|
|
241
266
|
return {
|
|
242
267
|
data: result,
|
|
@@ -298,7 +323,7 @@ export class CacheInterceptor implements NestInterceptor {
|
|
|
298
323
|
private static cache = new Map<string, CacheEntry>();
|
|
299
324
|
private static cleanupInterval: Timer | null = null;
|
|
300
325
|
|
|
301
|
-
constructor(private ttlMs
|
|
326
|
+
constructor(private ttlMs = 60000) {
|
|
302
327
|
// Setup periodic cleanup of expired entries
|
|
303
328
|
CacheInterceptor.setupCleanup();
|
|
304
329
|
}
|
|
@@ -410,7 +435,9 @@ export interface InterceptorExecutorOptions {
|
|
|
410
435
|
/** Interceptors from method */
|
|
411
436
|
methodInterceptors?: Interceptor[];
|
|
412
437
|
/** Container for resolving interceptor instances */
|
|
413
|
-
resolveInterceptor?: (
|
|
438
|
+
resolveInterceptor?: (
|
|
439
|
+
interceptor: Interceptor,
|
|
440
|
+
) => NestInterceptor | InterceptorFn | null;
|
|
414
441
|
}
|
|
415
442
|
|
|
416
443
|
/**
|
|
@@ -420,7 +447,9 @@ function createCallHandler(
|
|
|
420
447
|
interceptors: Array<NestInterceptor | InterceptorFn>,
|
|
421
448
|
context: Context,
|
|
422
449
|
finalHandler: () => Promise<unknown>,
|
|
423
|
-
resolveInterceptor?: (
|
|
450
|
+
resolveInterceptor?: (
|
|
451
|
+
interceptor: Interceptor,
|
|
452
|
+
) => NestInterceptor | InterceptorFn | null,
|
|
424
453
|
): CallHandler {
|
|
425
454
|
let index = 0;
|
|
426
455
|
|
|
@@ -430,10 +459,15 @@ function createCallHandler(
|
|
|
430
459
|
}
|
|
431
460
|
|
|
432
461
|
const interceptor = interceptors[index++];
|
|
433
|
-
let interceptorInstance: NestInterceptor | InterceptorFn | null =
|
|
462
|
+
let interceptorInstance: NestInterceptor | InterceptorFn | null =
|
|
463
|
+
interceptor;
|
|
434
464
|
|
|
435
465
|
// Resolve if needed
|
|
436
|
-
if (
|
|
466
|
+
if (
|
|
467
|
+
resolveInterceptor &&
|
|
468
|
+
!isNestInterceptor(interceptor) &&
|
|
469
|
+
!isInterceptorFn(interceptor)
|
|
470
|
+
) {
|
|
437
471
|
interceptorInstance = resolveInterceptor(interceptor);
|
|
438
472
|
}
|
|
439
473
|
|
|
@@ -502,7 +536,10 @@ export async function executeInterceptors(
|
|
|
502
536
|
// Resolve the interceptor
|
|
503
537
|
if (typeof interceptor === "function") {
|
|
504
538
|
// Check if it's an interceptor function or a class constructor
|
|
505
|
-
const funcInterceptor = interceptor as {
|
|
539
|
+
const funcInterceptor = interceptor as {
|
|
540
|
+
prototype?: unknown;
|
|
541
|
+
intercept?: unknown;
|
|
542
|
+
};
|
|
506
543
|
if (
|
|
507
544
|
funcInterceptor.prototype &&
|
|
508
545
|
typeof funcInterceptor.prototype === "object" &&
|
|
@@ -512,7 +549,8 @@ export async function executeInterceptors(
|
|
|
512
549
|
instance = resolveInterceptor ? resolveInterceptor(interceptor) : null;
|
|
513
550
|
if (!instance) {
|
|
514
551
|
// Create a new instance if not in container
|
|
515
|
-
const InterceptorClass =
|
|
552
|
+
const InterceptorClass =
|
|
553
|
+
interceptor as unknown as new () => NestInterceptor;
|
|
516
554
|
instance = new InterceptorClass();
|
|
517
555
|
}
|
|
518
556
|
} else {
|
|
@@ -571,4 +609,4 @@ export function isNestInterceptor(value: unknown): value is NestInterceptor {
|
|
|
571
609
|
*/
|
|
572
610
|
export function isInterceptorFn(value: unknown): value is InterceptorFn {
|
|
573
611
|
return typeof value === "function" && !isNestInterceptor(value);
|
|
574
|
-
}
|
|
612
|
+
}
|
package/src/modules/lazy.ts
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* and reduced memory usage for large applications.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { Container,
|
|
9
|
-
import { Injectable } from "./metadata";
|
|
8
|
+
import type { Container, Provider, Token } from "../container";
|
|
10
9
|
import { Inject } from "./index";
|
|
10
|
+
import { Injectable } from "./metadata";
|
|
11
11
|
|
|
12
12
|
// ============= Types =============
|
|
13
13
|
|
|
@@ -166,7 +166,9 @@ export function LazyModule(loader: ModuleLoaderFn): ClassDecorator {
|
|
|
166
166
|
/**
|
|
167
167
|
* Token for the ModuleLoader service
|
|
168
168
|
*/
|
|
169
|
-
export const MODULE_LOADER_TOKEN = Symbol.for(
|
|
169
|
+
export const MODULE_LOADER_TOKEN = Symbol.for(
|
|
170
|
+
"ModuleLoader",
|
|
171
|
+
) as Token<ModuleLoader>;
|
|
170
172
|
|
|
171
173
|
/**
|
|
172
174
|
* Options for loading lazy modules
|
|
@@ -200,9 +202,7 @@ export class ModuleLoader {
|
|
|
200
202
|
private container: Container;
|
|
201
203
|
private loadedModules = new Set<Constructor>();
|
|
202
204
|
private moduleLoaders = new Map<Constructor, LazyModuleLoaderImpl>();
|
|
203
|
-
private onModuleLoadCallback?: (
|
|
204
|
-
moduleClass: Constructor,
|
|
205
|
-
) => Promise<void>;
|
|
205
|
+
private onModuleLoadCallback?: (moduleClass: Constructor) => Promise<void>;
|
|
206
206
|
|
|
207
207
|
constructor(container: Container) {
|
|
208
208
|
this.container = container;
|
|
@@ -230,9 +230,7 @@ export class ModuleLoader {
|
|
|
230
230
|
): Promise<void> {
|
|
231
231
|
// Normalize to Constructor if it's a token
|
|
232
232
|
const moduleClass =
|
|
233
|
-
typeof moduleToken === "function"
|
|
234
|
-
? (moduleToken as Constructor)
|
|
235
|
-
: null;
|
|
233
|
+
typeof moduleToken === "function" ? (moduleToken as Constructor) : null;
|
|
236
234
|
|
|
237
235
|
if (!moduleClass) {
|
|
238
236
|
throw new Error("Module token must be a class constructor");
|
|
@@ -385,9 +383,7 @@ export function createLazyLoader(
|
|
|
385
383
|
const module = await importFn();
|
|
386
384
|
const moduleClass = module[exportName] as Constructor;
|
|
387
385
|
if (!moduleClass) {
|
|
388
|
-
throw new Error(
|
|
389
|
-
`Export "${exportName}" not found in lazy loaded module`,
|
|
390
|
-
);
|
|
386
|
+
throw new Error(`Export "${exportName}" not found in lazy loaded module`);
|
|
391
387
|
}
|
|
392
388
|
return moduleClass;
|
|
393
389
|
};
|
|
@@ -396,9 +392,7 @@ export function createLazyLoader(
|
|
|
396
392
|
/**
|
|
397
393
|
* Check if all lazy modules in a list are loaded
|
|
398
394
|
*/
|
|
399
|
-
export function areAllLazyModulesLoaded(
|
|
400
|
-
modules: Constructor[],
|
|
401
|
-
): boolean {
|
|
395
|
+
export function areAllLazyModulesLoaded(modules: Constructor[]): boolean {
|
|
402
396
|
return modules.every((module) => {
|
|
403
397
|
const metadata = getLazyMetadata(module);
|
|
404
398
|
return !metadata || metadata.loaded;
|
|
@@ -408,11 +402,9 @@ export function areAllLazyModulesLoaded(
|
|
|
408
402
|
/**
|
|
409
403
|
* Get list of unloaded lazy modules
|
|
410
404
|
*/
|
|
411
|
-
export function getUnloadedLazyModules(
|
|
412
|
-
modules: Constructor[],
|
|
413
|
-
): Constructor[] {
|
|
405
|
+
export function getUnloadedLazyModules(modules: Constructor[]): Constructor[] {
|
|
414
406
|
return modules.filter((module) => {
|
|
415
407
|
const metadata = getLazyMetadata(module);
|
|
416
408
|
return metadata && !metadata.loaded;
|
|
417
409
|
});
|
|
418
|
-
}
|
|
410
|
+
}
|
package/src/modules/lifecycle.ts
CHANGED
|
@@ -104,7 +104,9 @@ export function isOnApplicationBootstrap(
|
|
|
104
104
|
/**
|
|
105
105
|
* Check if an instance implements OnModuleDestroy
|
|
106
106
|
*/
|
|
107
|
-
export function isOnModuleDestroy(
|
|
107
|
+
export function isOnModuleDestroy(
|
|
108
|
+
instance: unknown,
|
|
109
|
+
): instance is OnModuleDestroy {
|
|
108
110
|
return (
|
|
109
111
|
typeof instance === "object" &&
|
|
110
112
|
instance !== null &&
|
|
@@ -123,8 +125,8 @@ export function isBeforeApplicationShutdown(
|
|
|
123
125
|
typeof instance === "object" &&
|
|
124
126
|
instance !== null &&
|
|
125
127
|
"beforeApplicationShutdown" in instance &&
|
|
126
|
-
typeof (instance as BeforeApplicationShutdown)
|
|
127
|
-
|
|
128
|
+
typeof (instance as BeforeApplicationShutdown).beforeApplicationShutdown ===
|
|
129
|
+
"function"
|
|
128
130
|
);
|
|
129
131
|
}
|
|
130
132
|
|
|
@@ -146,7 +148,9 @@ export function isOnApplicationShutdown(
|
|
|
146
148
|
/**
|
|
147
149
|
* Check if an instance implements OnBeforeRequest
|
|
148
150
|
*/
|
|
149
|
-
export function isOnBeforeRequest(
|
|
151
|
+
export function isOnBeforeRequest(
|
|
152
|
+
instance: unknown,
|
|
153
|
+
): instance is OnBeforeRequest {
|
|
150
154
|
return (
|
|
151
155
|
typeof instance === "object" &&
|
|
152
156
|
instance !== null &&
|
|
@@ -158,7 +162,9 @@ export function isOnBeforeRequest(instance: unknown): instance is OnBeforeReques
|
|
|
158
162
|
/**
|
|
159
163
|
* Check if an instance implements OnAfterRequest
|
|
160
164
|
*/
|
|
161
|
-
export function isOnAfterRequest(
|
|
165
|
+
export function isOnAfterRequest(
|
|
166
|
+
instance: unknown,
|
|
167
|
+
): instance is OnAfterRequest {
|
|
162
168
|
return (
|
|
163
169
|
typeof instance === "object" &&
|
|
164
170
|
instance !== null &&
|
|
@@ -170,7 +176,9 @@ export function isOnAfterRequest(instance: unknown): instance is OnAfterRequest
|
|
|
170
176
|
/**
|
|
171
177
|
* Check if an instance implements OnRequestError
|
|
172
178
|
*/
|
|
173
|
-
export function isOnRequestError(
|
|
179
|
+
export function isOnRequestError(
|
|
180
|
+
instance: unknown,
|
|
181
|
+
): instance is OnRequestError {
|
|
174
182
|
return (
|
|
175
183
|
typeof instance === "object" &&
|
|
176
184
|
instance !== null &&
|
|
@@ -475,4 +483,4 @@ export interface RequestLifecycle
|
|
|
475
483
|
/**
|
|
476
484
|
* Combined interface for all lifecycle hooks.
|
|
477
485
|
*/
|
|
478
|
-
export interface FullLifecycle extends ApplicationLifecycle, RequestLifecycle {}
|
|
486
|
+
export interface FullLifecycle extends ApplicationLifecycle, RequestLifecycle {}
|
package/src/modules/metadata.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* This module has no dependencies on other module files.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type {
|
|
8
|
+
import type { Provider, Token } from "../container";
|
|
9
9
|
|
|
10
10
|
// Type alias for class constructors
|
|
11
11
|
type Constructor = new (...args: unknown[]) => unknown;
|
|
@@ -24,14 +24,21 @@ export interface ModuleMetadata {
|
|
|
24
24
|
// Simple metadata storage without Reflect.metadata
|
|
25
25
|
const metadataStore = new WeakMap<Constructor, Map<string, unknown>>();
|
|
26
26
|
|
|
27
|
-
export function setMetadata(
|
|
27
|
+
export function setMetadata(
|
|
28
|
+
target: Constructor,
|
|
29
|
+
key: string,
|
|
30
|
+
value: unknown,
|
|
31
|
+
): void {
|
|
28
32
|
if (!metadataStore.has(target)) {
|
|
29
33
|
metadataStore.set(target, new Map());
|
|
30
34
|
}
|
|
31
35
|
metadataStore.get(target)?.set(key, value);
|
|
32
36
|
}
|
|
33
37
|
|
|
34
|
-
export function getMetadata<T>(
|
|
38
|
+
export function getMetadata<T>(
|
|
39
|
+
target: Constructor,
|
|
40
|
+
key: string,
|
|
41
|
+
): T | undefined {
|
|
35
42
|
return metadataStore.get(target)?.get(key) as T | undefined;
|
|
36
43
|
}
|
|
37
44
|
|
|
@@ -49,7 +56,10 @@ export function setPrototypeMetadata(
|
|
|
49
56
|
prototypeMetadataStore.get(target)?.set(key, value);
|
|
50
57
|
}
|
|
51
58
|
|
|
52
|
-
export function getPrototypeMetadata<T>(
|
|
59
|
+
export function getPrototypeMetadata<T>(
|
|
60
|
+
target: object,
|
|
61
|
+
key: string,
|
|
62
|
+
): T | undefined {
|
|
53
63
|
return prototypeMetadataStore.get(target)?.get(key) as T | undefined;
|
|
54
64
|
}
|
|
55
65
|
|
|
@@ -87,4 +97,4 @@ export function Module(metadata: ModuleMetadata): ClassDecorator {
|
|
|
87
97
|
}
|
|
88
98
|
|
|
89
99
|
// Export the Constructor type for use in other modules
|
|
90
|
-
export type { Constructor };
|
|
100
|
+
export type { Constructor };
|