@veloxts/core 0.6.87 → 0.6.89

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @veloxts/core
2
2
 
3
+ ## 0.6.89
4
+
5
+ ### Patch Changes
6
+
7
+ - expand preset system with server config, auth presets, and security validation
8
+
9
+ ## 0.6.88
10
+
11
+ ### Patch Changes
12
+
13
+ - add ecosystem presets for environment-aware configuration
14
+
3
15
  ## 0.6.87
4
16
 
5
17
  ### Patch Changes
package/dist/app.js CHANGED
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import fastify from 'fastify';
7
7
  import fp from 'fastify-plugin';
8
- import { createContext } from './context.js';
8
+ import { setupContextHook } from './context.js';
9
9
  import { container } from './di/index.js';
10
10
  import { isVeloxError, VeloxError } from './errors.js';
11
11
  import { isFastifyPlugin, isVeloxPlugin, validatePluginMetadata } from './plugin.js';
@@ -163,14 +163,7 @@ export class VeloxApp {
163
163
  * @internal
164
164
  */
165
165
  _setupContext() {
166
- // Create context for each request via direct assignment
167
- // TypeScript's declaration merging provides type safety
168
- this._server.addHook('onRequest', async (request, reply) => {
169
- // Direct assignment is ~100-400ns faster than Object.defineProperty
170
- // We use a mutable type assertion here because this is the framework's
171
- // initialization code - the readonly constraint is for user code safety
172
- request.context = createContext(request, reply);
173
- });
166
+ setupContextHook(this._server);
174
167
  }
175
168
  /**
176
169
  * Sets up global error handling
package/dist/context.d.ts CHANGED
@@ -72,6 +72,17 @@ export declare function createContext(request: FastifyRequest, reply: FastifyRep
72
72
  * ```
73
73
  */
74
74
  export declare function isContext(value: unknown): value is BaseContext;
75
+ /**
76
+ * Sets up the context hook on a Fastify server
77
+ *
78
+ * This is the internal implementation used by both VeloxApp and setupTestContext
79
+ * to populate `request.context` on every request.
80
+ *
81
+ * @param server - Fastify server instance
82
+ *
83
+ * @internal
84
+ */
85
+ export declare function setupContextHook(server: FastifyInstance): void;
75
86
  /**
76
87
  * Sets up the test context hook on a Fastify server
77
88
  *
package/dist/context.js CHANGED
@@ -54,6 +54,26 @@ export function isContext(value) {
54
54
  typeof ctx.reply === 'object' &&
55
55
  ctx.reply !== null);
56
56
  }
57
+ /**
58
+ * Sets up the context hook on a Fastify server
59
+ *
60
+ * This is the internal implementation used by both VeloxApp and setupTestContext
61
+ * to populate `request.context` on every request.
62
+ *
63
+ * @param server - Fastify server instance
64
+ *
65
+ * @internal
66
+ */
67
+ export function setupContextHook(server) {
68
+ // Create context for each request via direct assignment
69
+ // TypeScript's declaration merging provides type safety
70
+ server.addHook('onRequest', async (request, reply) => {
71
+ // Direct assignment is ~100-400ns faster than Object.defineProperty
72
+ // We use a mutable type assertion here because this is the framework's
73
+ // initialization code - the readonly constraint is for user code safety
74
+ request.context = createContext(request, reply);
75
+ });
76
+ }
57
77
  /**
58
78
  * Sets up the test context hook on a Fastify server
59
79
  *
@@ -79,7 +99,5 @@ export function isContext(value) {
79
99
  * ```
80
100
  */
81
101
  export function setupTestContext(server) {
82
- server.addHook('onRequest', async (request, reply) => {
83
- request.context = createContext(request, reply);
84
- });
102
+ setupContextHook(server);
85
103
  }
@@ -174,6 +174,23 @@ export declare class Container {
174
174
  * @returns The normalized provider or undefined
175
175
  */
176
176
  getProvider<T>(token: InjectionToken<T>): NormalizedProvider<T> | undefined;
177
+ /**
178
+ * Validates token and retrieves provider with circular dependency checking
179
+ *
180
+ * This is the shared resolution logic used by both resolve() and resolveAsync().
181
+ * It handles:
182
+ * - Token validation
183
+ * - Circular dependency detection
184
+ * - Provider lookup (local and parent)
185
+ * - Auto-registration for unregistered class tokens
186
+ *
187
+ * @param token - The token to resolve
188
+ * @returns The normalized provider for the token
189
+ * @throws {VeloxError} If circular dependency detected or no provider found
190
+ *
191
+ * @internal
192
+ */
193
+ private getValidatedProvider;
177
194
  /**
178
195
  * Resolves a service from the container
179
196
  *
@@ -176,23 +176,22 @@ export class Container {
176
176
  // Resolution
177
177
  // ==========================================================================
178
178
  /**
179
- * Resolves a service from the container
179
+ * Validates token and retrieves provider with circular dependency checking
180
180
  *
181
- * @param token - The token to resolve
182
- * @param context - Optional resolution context (for request scope)
183
- * @returns The resolved service instance
184
- * @throws {VeloxError} If the service cannot be resolved
181
+ * This is the shared resolution logic used by both resolve() and resolveAsync().
182
+ * It handles:
183
+ * - Token validation
184
+ * - Circular dependency detection
185
+ * - Provider lookup (local and parent)
186
+ * - Auto-registration for unregistered class tokens
185
187
  *
186
- * @example
187
- * ```typescript
188
- * // Basic resolution
189
- * const userService = container.resolve(UserService);
188
+ * @param token - The token to resolve
189
+ * @returns The normalized provider for the token
190
+ * @throws {VeloxError} If circular dependency detected or no provider found
190
191
  *
191
- * // With request context (for request-scoped services)
192
- * const userContext = container.resolve(UserContext, { request });
193
- * ```
192
+ * @internal
194
193
  */
195
- resolve(token, context) {
194
+ getValidatedProvider(token) {
196
195
  validateToken(token);
197
196
  // Check for circular dependencies
198
197
  if (this.resolutionStack.has(token)) {
@@ -212,7 +211,27 @@ export class Container {
212
211
  throw new VeloxError(`No provider found for: ${getTokenName(token)}`, 500, 'SERVICE_NOT_FOUND');
213
212
  }
214
213
  }
215
- // Resolve based on scope
214
+ return provider;
215
+ }
216
+ /**
217
+ * Resolves a service from the container
218
+ *
219
+ * @param token - The token to resolve
220
+ * @param context - Optional resolution context (for request scope)
221
+ * @returns The resolved service instance
222
+ * @throws {VeloxError} If the service cannot be resolved
223
+ *
224
+ * @example
225
+ * ```typescript
226
+ * // Basic resolution
227
+ * const userService = container.resolve(UserService);
228
+ *
229
+ * // With request context (for request-scoped services)
230
+ * const userContext = container.resolve(UserContext, { request });
231
+ * ```
232
+ */
233
+ resolve(token, context) {
234
+ const provider = this.getValidatedProvider(token);
216
235
  return this.resolveWithScope(token, provider, context);
217
236
  }
218
237
  /**
@@ -435,23 +454,7 @@ export class Container {
435
454
  * ```
436
455
  */
437
456
  async resolveAsync(token, context) {
438
- validateToken(token);
439
- // Check for circular dependencies
440
- if (this.resolutionStack.has(token)) {
441
- const stack = [...this.resolutionStack].map((t) => getTokenName(t));
442
- const current = getTokenName(token);
443
- throw new VeloxError(`Circular dependency detected: ${[...stack, current].join(' -> ')}`, 500, 'CIRCULAR_DEPENDENCY');
444
- }
445
- // Get provider
446
- let provider = this.getProvider(token);
447
- if (!provider) {
448
- if (this.autoRegister && isClassToken(token)) {
449
- provider = this.tryAutoRegister(token);
450
- }
451
- if (!provider) {
452
- throw new VeloxError(`No provider found for: ${getTokenName(token)}`, 500, 'SERVICE_NOT_FOUND');
453
- }
454
- }
457
+ const provider = this.getValidatedProvider(token);
455
458
  return this.resolveWithScopeAsync(token, provider, context);
456
459
  }
457
460
  /**
package/dist/index.d.ts CHANGED
@@ -22,7 +22,7 @@ export type { FastifyLoggerOptions, FastifyReply, FastifyRequest } from 'fastify
22
22
  export type { StartOptions } from './app.js';
23
23
  export { VeloxApp, velox, veloxApp } from './app.js';
24
24
  export type { BaseContext } from './context.js';
25
- export { createContext, isContext, setupTestContext } from './context.js';
25
+ export { createContext, isContext, setupContextHook, setupTestContext } from './context.js';
26
26
  export type { AbstractClass, ClassConstructor, ClassProvider, ContainerOptions, ExistingProvider, FactoryProvider, InjectableOptions, InjectionToken, Provider, ResolutionContext, StringToken, SymbolToken, TokenType, ValueProvider, } from './di/index.js';
27
27
  export { asClass, asExisting, asFactory, asValue, Container, container, factory, getConstructorTokens, getExplicitInjectTokens, getInjectableScope, getOptionalParams, getTokenName, Inject, Injectable, isClassProvider, isClassToken, isExistingProvider, isFactoryProvider, isInjectable, isStringToken, isSymbolToken, isValueProvider, makeInjectable, Optional, Scope, ScopeManager, scoped, setInjectTokens, singleton, token, transient, validateProvider, validateToken, value, } from './di/index.js';
28
28
  export type { ErrorCode, ErrorResponse, GenericErrorResponse, InterpolationVars, NotFoundErrorResponse, ValidationErrorResponse, VeloxCoreErrorCode, VeloxErrorCode, VeloxErrorCodeRegistry, } from './errors.js';
package/dist/index.js CHANGED
@@ -24,7 +24,7 @@ const packageJson = require('../package.json');
24
24
  /** VeloxTS framework version */
25
25
  export const VELOX_VERSION = packageJson.version ?? '0.0.0-unknown';
26
26
  export { VeloxApp, velox, veloxApp } from './app.js';
27
- export { createContext, isContext, setupTestContext } from './context.js';
27
+ export { createContext, isContext, setupContextHook, setupTestContext } from './context.js';
28
28
  // Dependency Injection
29
29
  export { asClass, asExisting, asFactory, asValue, Container, container, factory, getConstructorTokens, getExplicitInjectTokens, getInjectableScope, getOptionalParams, getTokenName, Inject, Injectable, isClassProvider, isClassToken, isExistingProvider, isFactoryProvider, isInjectable, isStringToken, isSymbolToken, isValueProvider, makeInjectable, Optional, Scope, ScopeManager, scoped, setInjectTokens, singleton, token, transient, validateProvider, validateToken, value, } from './di/index.js';
30
30
  export { assertNever, ConfigurationError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veloxts/core",
3
- "version": "0.6.87",
3
+ "version": "0.6.89",
4
4
  "description": "Fastify wrapper, DI container, and plugin system for VeloxTS framework",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",