balda 0.0.60 → 0.0.62

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/lib/index.d.cts CHANGED
@@ -1638,6 +1638,34 @@ declare class GraphQL {
1638
1638
  private ensureTypeDefsArray;
1639
1639
  }
1640
1640
 
1641
+ declare class MockResponse<T = any> {
1642
+ readonly response: Response$1;
1643
+ constructor(response: Response$1);
1644
+ body(): T;
1645
+ statusCode(): number;
1646
+ headers(): Record<string, string>;
1647
+ cookies(): Record<string, string>;
1648
+ assertStatus(status: number): this;
1649
+ assertHeader(header: string, value: string): this;
1650
+ assertHeaderExists(header: string): this;
1651
+ assertHeaderNotExists(header: string): this;
1652
+ assertCookie(name: string, value: string): this;
1653
+ assertCookieExists(name: string): this;
1654
+ assertCookieNotExists(name: string): this;
1655
+ assertBodySubset(subset: Partial<T>): this;
1656
+ assertBodyDeepEqual(expected: T): this;
1657
+ assertBodyNotSubset(subset: Partial<T>): this;
1658
+ assertBodyNotDeepEqual(expected: T): this;
1659
+ assertCustom(assertion: (response: Response$1) => void): this;
1660
+ private assertSubset;
1661
+ private assertDeepEqual;
1662
+ private assertNotSubset;
1663
+ private assertNotDeepEqual;
1664
+ private assertArraySubset;
1665
+ private assertArrayDeepEqual;
1666
+ private isObject;
1667
+ }
1668
+
1641
1669
  declare class NativeFs {
1642
1670
  glob(...args: Parameters<typeof glob>): Promise<string[]>;
1643
1671
  mkdir(path: string, options?: {
@@ -1976,6 +2004,7 @@ declare class Server<H extends NodeHttpClient = NodeHttpClient> implements Serve
1976
2004
  isListening: boolean;
1977
2005
  isProduction: boolean;
1978
2006
  graphql: GraphQL;
2007
+ readonly inject: InjectFunction;
1979
2008
  /**
1980
2009
  * The constructor for the server
1981
2010
  * @warning Routes will only be defined after calling the `listen` method so you're free to define middlewares before calling it
@@ -2043,7 +2072,9 @@ declare class Server<H extends NodeHttpClient = NodeHttpClient> implements Serve
2043
2072
  * @returns A promise that resolves when the server is disconnected
2044
2073
  */
2045
2074
  disconnect(): Promise<void>;
2046
- getMockServer(options?: Pick<ServerOptions, "controllerPatterns">): Promise<MockServer>;
2075
+ getMockServer(options?: Pick<ServerOptions, "controllerPatterns">): MockServer;
2076
+ ensureBootstrapped(options?: Pick<ServerOptions, "controllerPatterns">): Promise<void>;
2077
+ private createInjectFunction;
2047
2078
  private importControllers;
2048
2079
  private applyPlugins;
2049
2080
  /**
@@ -2069,34 +2100,6 @@ declare class Server<H extends NodeHttpClient = NodeHttpClient> implements Serve
2069
2100
  private setupAbortSignalHandler;
2070
2101
  }
2071
2102
 
2072
- declare class MockResponse<T = any> {
2073
- readonly response: Response$1;
2074
- constructor(response: Response$1);
2075
- body(): T;
2076
- statusCode(): number;
2077
- headers(): Record<string, string>;
2078
- cookies(): Record<string, string>;
2079
- assertStatus(status: number): this;
2080
- assertHeader(header: string, value: string): this;
2081
- assertHeaderExists(header: string): this;
2082
- assertHeaderNotExists(header: string): this;
2083
- assertCookie(name: string, value: string): this;
2084
- assertCookieExists(name: string): this;
2085
- assertCookieNotExists(name: string): this;
2086
- assertBodySubset(subset: Partial<T>): this;
2087
- assertBodyDeepEqual(expected: T): this;
2088
- assertBodyNotSubset(subset: Partial<T>): this;
2089
- assertBodyNotDeepEqual(expected: T): this;
2090
- assertCustom(assertion: (response: Response$1) => void): this;
2091
- private assertSubset;
2092
- private assertDeepEqual;
2093
- private assertNotSubset;
2094
- private assertNotDeepEqual;
2095
- private assertArraySubset;
2096
- private assertArrayDeepEqual;
2097
- private isObject;
2098
- }
2099
-
2100
2103
  /**
2101
2104
  * Type-safe options for the mock server
2102
2105
  * @template TBody - The request body type
@@ -2140,7 +2143,8 @@ declare class MockServer {
2140
2143
  readonly server: Server<NodeHttpClient>;
2141
2144
  private readonly logger;
2142
2145
  private ensureGraphQLHandler;
2143
- constructor(server: Server<NodeHttpClient>);
2146
+ private readonly bootstrapOptions?;
2147
+ constructor(server: Server<NodeHttpClient>, options?: Pick<ServerOptions, "controllerPatterns">);
2144
2148
  /**
2145
2149
  * Simulates an HTTP request without making an actual network call, useful for testing purposes
2146
2150
  * Executes the middleware chain and handler of the route
@@ -2702,6 +2706,49 @@ type ResolvedServerOptions = {
2702
2706
  abortSignal?: AbortSignal;
2703
2707
  };
2704
2708
  type ServerErrorHandler = (req: Request, res: Response$1, next: NextFunction, error: Error) => SyncOrAsync;
2709
+ /**
2710
+ * A callable function with HTTP method shortcuts for injecting requests directly into the server.
2711
+ * Similar to Fastify's `inject`, it allows testing routes without network overhead.
2712
+ */
2713
+ interface InjectFunction {
2714
+ /**
2715
+ * Simulates an HTTP request without making an actual network call
2716
+ * @param method - The HTTP method (GET, POST, PUT, DELETE, PATCH)
2717
+ * @param path - The request path
2718
+ * @param options - Request options including body, headers, query params, etc.
2719
+ */
2720
+ <TResponse = any, TBody = any, TQuery extends Record<string, string> = any>(method: HttpMethod, path: string, options?: MockServerOptions<TBody, TQuery>): Promise<MockResponse<TResponse>>;
2721
+ /**
2722
+ * Type-safe GET request
2723
+ * @example
2724
+ * const res = await server.inject.get<UserResponse>("/users");
2725
+ */
2726
+ get<TResponse = any, TQuery extends Record<string, string> = any>(path: string, options?: Omit<MockServerOptions<never, TQuery>, "body" | "formData" | "urlencoded">): Promise<MockResponse<TResponse>>;
2727
+ /**
2728
+ * Type-safe POST request
2729
+ * @example
2730
+ * const res = await server.inject.post<UserResponse, CreateUserInput>("/users", { body: { name: "John" } });
2731
+ */
2732
+ post<TResponse = any, TBody = any, TQuery extends Record<string, string> = any>(path: string, options?: MockServerOptions<TBody, TQuery>): Promise<MockResponse<TResponse>>;
2733
+ /**
2734
+ * Type-safe PUT request
2735
+ * @example
2736
+ * const res = await server.inject.put<UserResponse>("/users/1", { body: { name: "Jane" } });
2737
+ */
2738
+ put<TResponse = any, TBody = any, TQuery extends Record<string, string> = any>(path: string, options?: MockServerOptions<TBody, TQuery>): Promise<MockResponse<TResponse>>;
2739
+ /**
2740
+ * Type-safe PATCH request
2741
+ * @example
2742
+ * const res = await server.inject.patch<UserResponse>("/users/1", { body: { name: "Jane" } });
2743
+ */
2744
+ patch<TResponse = any, TBody = any, TQuery extends Record<string, string> = any>(path: string, options?: MockServerOptions<TBody, TQuery>): Promise<MockResponse<TResponse>>;
2745
+ /**
2746
+ * Type-safe DELETE request
2747
+ * @example
2748
+ * const res = await server.inject.delete<DeleteResponse>("/users/1");
2749
+ */
2750
+ delete<TResponse = any, TQuery extends Record<string, string> = any>(path: string, options?: Omit<MockServerOptions<never, TQuery>, "body" | "formData">): Promise<MockResponse<TResponse>>;
2751
+ }
2705
2752
  interface ServerInterface {
2706
2753
  /**
2707
2754
  * Identifier for the balda server instance
@@ -2975,12 +3022,35 @@ interface ServerInterface {
2975
3022
  */
2976
3023
  disconnect: () => Promise<void>;
2977
3024
  /**
2978
- * Returns a mock server instance that can be used to test the server without starting it
2979
- * It will import the controllers and apply the plugins to the mock server
3025
+ * Returns a mock server instance that can be used to test the server without starting it.
3026
+ * The mock server lazily bootstraps (imports controllers, applies plugins) on the first request.
2980
3027
  * @param options - The options for the mock server
2981
3028
  * @param options.controllerPatterns - Custom controller patterns to import if the mock server must not be initialized with the same controller patterns as the server
2982
3029
  */
2983
- getMockServer: () => Promise<MockServer>;
3030
+ getMockServer: (options?: Pick<ServerOptions, "controllerPatterns">) => MockServer;
3031
+ /**
3032
+ * Inject requests directly into the server without network overhead.
3033
+ * Lazily bootstraps the server on the first call.
3034
+ * Supports both generic `inject(method, path, options)` and typed shortcuts like `inject.get()`, `inject.post()`, etc.
3035
+ *
3036
+ * @example
3037
+ * ```typescript
3038
+ * // Generic inject
3039
+ * const res = await server.inject("GET", "/users");
3040
+ *
3041
+ * // Typed shortcuts
3042
+ * const res = await server.inject.get<User[]>("/users");
3043
+ * const res = await server.inject.post<User, CreateUserInput>("/users", { body: { name: "John" } });
3044
+ * ```
3045
+ */
3046
+ inject: InjectFunction;
3047
+ /**
3048
+ * Ensures the server is bootstrapped (controllers imported, plugins applied).
3049
+ * This is called lazily by `inject()` and `MockServer.request()`, but can be called explicitly to pre-bootstrap.
3050
+ * This method is idempotent — subsequent calls after the first have no effect.
3051
+ * @param options - Optional controller patterns to import
3052
+ */
3053
+ ensureBootstrapped: (options?: Pick<ServerOptions, "controllerPatterns">) => Promise<void>;
2984
3054
  /**
2985
3055
  * Exit current runtime process with the given code based on the current runtime
2986
3056
  * @param code - The code to exit with, defaults to 0
@@ -4745,6 +4815,15 @@ declare const timeout: (options: TimeoutOptions) => TypedMiddleware<{
4745
4815
  */
4746
4816
  declare const trustProxy: (options?: TrustProxyOptions) => ServerRouteMiddleware;
4747
4817
 
4818
+ /**
4819
+ * Middleware to parse the body of the request. GET, DELETE and OPTIONS requests are not parsed. Used internally by the server. If no parser is set, the body will be parsed as raw array buffer.
4820
+ * @param options - The options for the body parser middleware.
4821
+ * @param options.json - The options for the JSON middleware.
4822
+ * @param options.urlencoded - The options for the URL-encoded middleware.
4823
+ * @param options.fileParser - The options for the file parser middleware.
4824
+ */
4825
+ declare const bodyParser: (options?: BodyParserOptions) => ServerRouteMiddleware;
4826
+
4748
4827
  declare const createPolicyDecorator: <T extends Record<string, PolicyProvider>>(manager: PolicyManager<T>) => PolicyDecorator<T>;
4749
4828
 
4750
4829
  /**
@@ -4934,4 +5013,4 @@ declare enum CacheStatus {
4934
5013
  */
4935
5014
  declare const router: ClientRouter;
4936
5015
 
4937
- export { type AsyncLocalStorageContextSetters, AzureBlobStorageProvider, BaseCron, BasePlugin, type BaseStorageProviderOptions, type BlobStorageProviderOptions, type BodylessMethodOptions, BullMQConfiguration, type BullMQConfigurationOptions, BullMQPubSub, CACHE_STATUS_HEADER, type CacheKeyIncludes, type CacheMiddlewareOptions, type CachePluginOptions, type CacheProvider, type CacheRedisOptions, type CacheRouteConfig, CacheService, type CacheServiceInterface, type CacheStats, CacheStatus, Command, type CommandOptions, CommandRegistry, type CompressionOptions, type CookieMiddlewareOptions, type CorsOptions, type CronSchedule, type CronScheduleParams, CronService, type CronUIOptions, CustomAdapter, type CustomQueueConfiguration, type CustomStorageProviderOptions, CustomTypedQueue, type CustomValidationError, DEFAULT_CACHE_OPTIONS, EdgeAdapter, EjsAdapter, type ExtractParams, GraphQL, type GraphQLContext, type GraphQLOptions, type GraphQLResolverFunction, type GraphQLResolverMap, type GraphQLResolverType, type GraphQLResolvers, type GraphQLSchemaInput, type GraphQLTypeDef, type GroupRouter, HandlebarsAdapter, type HelmetOptions, type HttpMethod, type HttpsOptions, type InferMiddlewareExtension, type InferMiddlewareExtensions, type InferResponseMap, type InferSchemaType, LocalStorageProvider, type LocalStorageProviderOptions, type LockBehavior, type LogOptions, type LoggerOptions, type MailOptions, MailOptionsBuilder, MailProvider, type MailProviderInterface, Mailer, type MailerInterface, type MailerOptions, type MailerProviderOptions, MemoryCacheProvider, MemoryPubSub, type MethodOverrideOptions, MockResponse, MockServer, type MockServerOptions, type MqttConnectionOptions, type MqttHandler, type MqttPublishOptions, MqttService, type MqttSubscribeOptions, type MqttSubscription, type MqttTopics, MustacheAdapter, type NextFunction, type NodeHttpClient, type NodeServer as NodeHttpServerClient, PGBossConfiguration, type PGBossConfigurationOptions, PGBossPubSub, type PolicyDecorator, type PolicyErrorHandlerOptions, PolicyManager, type PolicyProvider, type PolicyRouteConfig, type PublishTopic, QueueManager, QueueService, type RateLimiterKeyOptions, RedisCacheProvider, Request, type RequestSchema, Response$1 as Response, type ResponseBodyForStatus, type RuntimeServer, S3StorageProvider, type S3StorageProviderOptions, SQSConfiguration, type SQSConfigurationOptions, SQSPubSub, type CacheMetrics as SchemaCacheMetrics, type SerializeOptions, type SerializedValidationError, Server, type ServerConnectInput, type ServerErrorHandler, type ServerHook, type ServerInterface, type ServerListenCallback, type ServerOptions, type ServerPlugin, type ServerPluginConfig, type ServerRouteHandler, type ServerRouteMiddleware, type ServerTapOptions, type SessionOptions, type SignalEvent, type StandardMethodOptions, type StaticPluginOptions, Storage, type StorageInterface, type StorageOptions, type StorageProviderOptions, type TemplateMailOptions, type TimeoutOptions, type TrustProxyOptions, type TypedCacheKeyIncludes, type TypedCacheRouteConfig, type TypedHandler, type TypedMiddleware, TypedQueue, type TypedRouteMetadata, type ValidatedData, type ValidationErrorHandlerOptions, type ValidationOptions, arg, asyncLocalStorage, asyncStorage, bullmqQueue, cache, cacheMiddleware, clearAllCaches as clearAllSchemaCaches, commandRegistry, compression, controller, cookie, cors, createExpressAdapter, createPolicyDecorator, createQueue, cron, cronUIInstance, cronUi, Server as default, defineMiddleware, defineQueueConfiguration, del, expressHandler, expressMiddleware, flag, get, getCacheService, getCacheMetrics as getSchemaCacheMetrics, hash, helmet, initCacheService, log, logCacheMetrics as logSchemaCacheMetrics, logger, memoryQueue, methodOverride, middleware, mountExpressRouter, mqtt, patch, pgbossQueue, post, put, rateLimiter, resetCacheService, router, serialize, serveStatic, session, setCronGlobalErrorHandler, setMqttGlobalErrorHandler, sqsQueue, timeout as timeoutMw, trustProxy, validate };
5016
+ export { type AsyncLocalStorageContextSetters, AzureBlobStorageProvider, BaseCron, BasePlugin, type BaseStorageProviderOptions, type BlobStorageProviderOptions, type BodyParserOptions, type BodylessMethodOptions, BullMQConfiguration, type BullMQConfigurationOptions, BullMQPubSub, CACHE_STATUS_HEADER, type CacheKeyIncludes, type CacheMiddlewareOptions, type CachePluginOptions, type CacheProvider, type CacheRedisOptions, type CacheRouteConfig, CacheService, type CacheServiceInterface, type CacheStats, CacheStatus, Command, type CommandOptions, CommandRegistry, type CompressionOptions, type CookieMiddlewareOptions, type CorsOptions, type CronSchedule, type CronScheduleParams, CronService, type CronUIOptions, CustomAdapter, type CustomQueueConfiguration, type CustomStorageProviderOptions, CustomTypedQueue, type CustomValidationError, DEFAULT_CACHE_OPTIONS, EdgeAdapter, EjsAdapter, type ExtractParams, GraphQL, type GraphQLContext, type GraphQLOptions, type GraphQLResolverFunction, type GraphQLResolverMap, type GraphQLResolverType, type GraphQLResolvers, type GraphQLSchemaInput, type GraphQLTypeDef, type GroupRouter, HandlebarsAdapter, type HelmetOptions, type HttpMethod, type HttpsOptions, type InferMiddlewareExtension, type InferMiddlewareExtensions, type InferResponseMap, type InferSchemaType, type InjectFunction, LocalStorageProvider, type LocalStorageProviderOptions, type LockBehavior, type LogOptions, type LoggerOptions, type MailOptions, MailOptionsBuilder, MailProvider, type MailProviderInterface, Mailer, type MailerInterface, type MailerOptions, type MailerProviderOptions, MemoryCacheProvider, MemoryPubSub, type MethodOverrideOptions, MockResponse, MockServer, type MockServerOptions, type MqttConnectionOptions, type MqttHandler, type MqttPublishOptions, MqttService, type MqttSubscribeOptions, type MqttSubscription, type MqttTopics, MustacheAdapter, type NextFunction, type NodeHttpClient, type NodeServer as NodeHttpServerClient, PGBossConfiguration, type PGBossConfigurationOptions, PGBossPubSub, type PolicyDecorator, type PolicyErrorHandlerOptions, PolicyManager, type PolicyProvider, type PolicyRouteConfig, type PublishTopic, QueueManager, QueueService, type RateLimiterKeyOptions, RedisCacheProvider, Request, type RequestSchema, Response$1 as Response, type ResponseBodyForStatus, type RuntimeServer, S3StorageProvider, type S3StorageProviderOptions, SQSConfiguration, type SQSConfigurationOptions, SQSPubSub, type CacheMetrics as SchemaCacheMetrics, type SerializeOptions, type SerializedValidationError, Server, type ServerConnectInput, type ServerErrorHandler, type ServerHook, type ServerInterface, type ServerListenCallback, type ServerOptions, type ServerPlugin, type ServerPluginConfig, type ServerRouteHandler, type ServerRouteMiddleware, type ServerTapOptions, type SessionOptions, type SignalEvent, type StandardMethodOptions, type StaticPluginOptions, Storage, type StorageInterface, type StorageOptions, type StorageProviderOptions, type TemplateMailOptions, type TimeoutOptions, type TrustProxyOptions, type TypedCacheKeyIncludes, type TypedCacheRouteConfig, type TypedHandler, type TypedMiddleware, TypedQueue, type TypedRouteMetadata, type ValidatedData, type ValidationErrorHandlerOptions, type ValidationOptions, arg, asyncLocalStorage, asyncStorage, bodyParser, bullmqQueue, cache, cacheMiddleware, clearAllCaches as clearAllSchemaCaches, commandRegistry, compression, controller, cookie, cors, createExpressAdapter, createPolicyDecorator, createQueue, cron, cronUIInstance, cronUi, Server as default, defineMiddleware, defineQueueConfiguration, del, expressHandler, expressMiddleware, flag, get, getCacheService, getCacheMetrics as getSchemaCacheMetrics, hash, helmet, initCacheService, log, logCacheMetrics as logSchemaCacheMetrics, logger, memoryQueue, methodOverride, middleware, mountExpressRouter, mqtt, patch, pgbossQueue, post, put, rateLimiter, resetCacheService, router, serialize, serveStatic, session, setCronGlobalErrorHandler, setMqttGlobalErrorHandler, sqsQueue, timeout as timeoutMw, trustProxy, validate };
package/lib/index.d.ts CHANGED
@@ -1638,6 +1638,34 @@ declare class GraphQL {
1638
1638
  private ensureTypeDefsArray;
1639
1639
  }
1640
1640
 
1641
+ declare class MockResponse<T = any> {
1642
+ readonly response: Response$1;
1643
+ constructor(response: Response$1);
1644
+ body(): T;
1645
+ statusCode(): number;
1646
+ headers(): Record<string, string>;
1647
+ cookies(): Record<string, string>;
1648
+ assertStatus(status: number): this;
1649
+ assertHeader(header: string, value: string): this;
1650
+ assertHeaderExists(header: string): this;
1651
+ assertHeaderNotExists(header: string): this;
1652
+ assertCookie(name: string, value: string): this;
1653
+ assertCookieExists(name: string): this;
1654
+ assertCookieNotExists(name: string): this;
1655
+ assertBodySubset(subset: Partial<T>): this;
1656
+ assertBodyDeepEqual(expected: T): this;
1657
+ assertBodyNotSubset(subset: Partial<T>): this;
1658
+ assertBodyNotDeepEqual(expected: T): this;
1659
+ assertCustom(assertion: (response: Response$1) => void): this;
1660
+ private assertSubset;
1661
+ private assertDeepEqual;
1662
+ private assertNotSubset;
1663
+ private assertNotDeepEqual;
1664
+ private assertArraySubset;
1665
+ private assertArrayDeepEqual;
1666
+ private isObject;
1667
+ }
1668
+
1641
1669
  declare class NativeFs {
1642
1670
  glob(...args: Parameters<typeof glob>): Promise<string[]>;
1643
1671
  mkdir(path: string, options?: {
@@ -1976,6 +2004,7 @@ declare class Server<H extends NodeHttpClient = NodeHttpClient> implements Serve
1976
2004
  isListening: boolean;
1977
2005
  isProduction: boolean;
1978
2006
  graphql: GraphQL;
2007
+ readonly inject: InjectFunction;
1979
2008
  /**
1980
2009
  * The constructor for the server
1981
2010
  * @warning Routes will only be defined after calling the `listen` method so you're free to define middlewares before calling it
@@ -2043,7 +2072,9 @@ declare class Server<H extends NodeHttpClient = NodeHttpClient> implements Serve
2043
2072
  * @returns A promise that resolves when the server is disconnected
2044
2073
  */
2045
2074
  disconnect(): Promise<void>;
2046
- getMockServer(options?: Pick<ServerOptions, "controllerPatterns">): Promise<MockServer>;
2075
+ getMockServer(options?: Pick<ServerOptions, "controllerPatterns">): MockServer;
2076
+ ensureBootstrapped(options?: Pick<ServerOptions, "controllerPatterns">): Promise<void>;
2077
+ private createInjectFunction;
2047
2078
  private importControllers;
2048
2079
  private applyPlugins;
2049
2080
  /**
@@ -2069,34 +2100,6 @@ declare class Server<H extends NodeHttpClient = NodeHttpClient> implements Serve
2069
2100
  private setupAbortSignalHandler;
2070
2101
  }
2071
2102
 
2072
- declare class MockResponse<T = any> {
2073
- readonly response: Response$1;
2074
- constructor(response: Response$1);
2075
- body(): T;
2076
- statusCode(): number;
2077
- headers(): Record<string, string>;
2078
- cookies(): Record<string, string>;
2079
- assertStatus(status: number): this;
2080
- assertHeader(header: string, value: string): this;
2081
- assertHeaderExists(header: string): this;
2082
- assertHeaderNotExists(header: string): this;
2083
- assertCookie(name: string, value: string): this;
2084
- assertCookieExists(name: string): this;
2085
- assertCookieNotExists(name: string): this;
2086
- assertBodySubset(subset: Partial<T>): this;
2087
- assertBodyDeepEqual(expected: T): this;
2088
- assertBodyNotSubset(subset: Partial<T>): this;
2089
- assertBodyNotDeepEqual(expected: T): this;
2090
- assertCustom(assertion: (response: Response$1) => void): this;
2091
- private assertSubset;
2092
- private assertDeepEqual;
2093
- private assertNotSubset;
2094
- private assertNotDeepEqual;
2095
- private assertArraySubset;
2096
- private assertArrayDeepEqual;
2097
- private isObject;
2098
- }
2099
-
2100
2103
  /**
2101
2104
  * Type-safe options for the mock server
2102
2105
  * @template TBody - The request body type
@@ -2140,7 +2143,8 @@ declare class MockServer {
2140
2143
  readonly server: Server<NodeHttpClient>;
2141
2144
  private readonly logger;
2142
2145
  private ensureGraphQLHandler;
2143
- constructor(server: Server<NodeHttpClient>);
2146
+ private readonly bootstrapOptions?;
2147
+ constructor(server: Server<NodeHttpClient>, options?: Pick<ServerOptions, "controllerPatterns">);
2144
2148
  /**
2145
2149
  * Simulates an HTTP request without making an actual network call, useful for testing purposes
2146
2150
  * Executes the middleware chain and handler of the route
@@ -2702,6 +2706,49 @@ type ResolvedServerOptions = {
2702
2706
  abortSignal?: AbortSignal;
2703
2707
  };
2704
2708
  type ServerErrorHandler = (req: Request, res: Response$1, next: NextFunction, error: Error) => SyncOrAsync;
2709
+ /**
2710
+ * A callable function with HTTP method shortcuts for injecting requests directly into the server.
2711
+ * Similar to Fastify's `inject`, it allows testing routes without network overhead.
2712
+ */
2713
+ interface InjectFunction {
2714
+ /**
2715
+ * Simulates an HTTP request without making an actual network call
2716
+ * @param method - The HTTP method (GET, POST, PUT, DELETE, PATCH)
2717
+ * @param path - The request path
2718
+ * @param options - Request options including body, headers, query params, etc.
2719
+ */
2720
+ <TResponse = any, TBody = any, TQuery extends Record<string, string> = any>(method: HttpMethod, path: string, options?: MockServerOptions<TBody, TQuery>): Promise<MockResponse<TResponse>>;
2721
+ /**
2722
+ * Type-safe GET request
2723
+ * @example
2724
+ * const res = await server.inject.get<UserResponse>("/users");
2725
+ */
2726
+ get<TResponse = any, TQuery extends Record<string, string> = any>(path: string, options?: Omit<MockServerOptions<never, TQuery>, "body" | "formData" | "urlencoded">): Promise<MockResponse<TResponse>>;
2727
+ /**
2728
+ * Type-safe POST request
2729
+ * @example
2730
+ * const res = await server.inject.post<UserResponse, CreateUserInput>("/users", { body: { name: "John" } });
2731
+ */
2732
+ post<TResponse = any, TBody = any, TQuery extends Record<string, string> = any>(path: string, options?: MockServerOptions<TBody, TQuery>): Promise<MockResponse<TResponse>>;
2733
+ /**
2734
+ * Type-safe PUT request
2735
+ * @example
2736
+ * const res = await server.inject.put<UserResponse>("/users/1", { body: { name: "Jane" } });
2737
+ */
2738
+ put<TResponse = any, TBody = any, TQuery extends Record<string, string> = any>(path: string, options?: MockServerOptions<TBody, TQuery>): Promise<MockResponse<TResponse>>;
2739
+ /**
2740
+ * Type-safe PATCH request
2741
+ * @example
2742
+ * const res = await server.inject.patch<UserResponse>("/users/1", { body: { name: "Jane" } });
2743
+ */
2744
+ patch<TResponse = any, TBody = any, TQuery extends Record<string, string> = any>(path: string, options?: MockServerOptions<TBody, TQuery>): Promise<MockResponse<TResponse>>;
2745
+ /**
2746
+ * Type-safe DELETE request
2747
+ * @example
2748
+ * const res = await server.inject.delete<DeleteResponse>("/users/1");
2749
+ */
2750
+ delete<TResponse = any, TQuery extends Record<string, string> = any>(path: string, options?: Omit<MockServerOptions<never, TQuery>, "body" | "formData">): Promise<MockResponse<TResponse>>;
2751
+ }
2705
2752
  interface ServerInterface {
2706
2753
  /**
2707
2754
  * Identifier for the balda server instance
@@ -2975,12 +3022,35 @@ interface ServerInterface {
2975
3022
  */
2976
3023
  disconnect: () => Promise<void>;
2977
3024
  /**
2978
- * Returns a mock server instance that can be used to test the server without starting it
2979
- * It will import the controllers and apply the plugins to the mock server
3025
+ * Returns a mock server instance that can be used to test the server without starting it.
3026
+ * The mock server lazily bootstraps (imports controllers, applies plugins) on the first request.
2980
3027
  * @param options - The options for the mock server
2981
3028
  * @param options.controllerPatterns - Custom controller patterns to import if the mock server must not be initialized with the same controller patterns as the server
2982
3029
  */
2983
- getMockServer: () => Promise<MockServer>;
3030
+ getMockServer: (options?: Pick<ServerOptions, "controllerPatterns">) => MockServer;
3031
+ /**
3032
+ * Inject requests directly into the server without network overhead.
3033
+ * Lazily bootstraps the server on the first call.
3034
+ * Supports both generic `inject(method, path, options)` and typed shortcuts like `inject.get()`, `inject.post()`, etc.
3035
+ *
3036
+ * @example
3037
+ * ```typescript
3038
+ * // Generic inject
3039
+ * const res = await server.inject("GET", "/users");
3040
+ *
3041
+ * // Typed shortcuts
3042
+ * const res = await server.inject.get<User[]>("/users");
3043
+ * const res = await server.inject.post<User, CreateUserInput>("/users", { body: { name: "John" } });
3044
+ * ```
3045
+ */
3046
+ inject: InjectFunction;
3047
+ /**
3048
+ * Ensures the server is bootstrapped (controllers imported, plugins applied).
3049
+ * This is called lazily by `inject()` and `MockServer.request()`, but can be called explicitly to pre-bootstrap.
3050
+ * This method is idempotent — subsequent calls after the first have no effect.
3051
+ * @param options - Optional controller patterns to import
3052
+ */
3053
+ ensureBootstrapped: (options?: Pick<ServerOptions, "controllerPatterns">) => Promise<void>;
2984
3054
  /**
2985
3055
  * Exit current runtime process with the given code based on the current runtime
2986
3056
  * @param code - The code to exit with, defaults to 0
@@ -4745,6 +4815,15 @@ declare const timeout: (options: TimeoutOptions) => TypedMiddleware<{
4745
4815
  */
4746
4816
  declare const trustProxy: (options?: TrustProxyOptions) => ServerRouteMiddleware;
4747
4817
 
4818
+ /**
4819
+ * Middleware to parse the body of the request. GET, DELETE and OPTIONS requests are not parsed. Used internally by the server. If no parser is set, the body will be parsed as raw array buffer.
4820
+ * @param options - The options for the body parser middleware.
4821
+ * @param options.json - The options for the JSON middleware.
4822
+ * @param options.urlencoded - The options for the URL-encoded middleware.
4823
+ * @param options.fileParser - The options for the file parser middleware.
4824
+ */
4825
+ declare const bodyParser: (options?: BodyParserOptions) => ServerRouteMiddleware;
4826
+
4748
4827
  declare const createPolicyDecorator: <T extends Record<string, PolicyProvider>>(manager: PolicyManager<T>) => PolicyDecorator<T>;
4749
4828
 
4750
4829
  /**
@@ -4934,4 +5013,4 @@ declare enum CacheStatus {
4934
5013
  */
4935
5014
  declare const router: ClientRouter;
4936
5015
 
4937
- export { type AsyncLocalStorageContextSetters, AzureBlobStorageProvider, BaseCron, BasePlugin, type BaseStorageProviderOptions, type BlobStorageProviderOptions, type BodylessMethodOptions, BullMQConfiguration, type BullMQConfigurationOptions, BullMQPubSub, CACHE_STATUS_HEADER, type CacheKeyIncludes, type CacheMiddlewareOptions, type CachePluginOptions, type CacheProvider, type CacheRedisOptions, type CacheRouteConfig, CacheService, type CacheServiceInterface, type CacheStats, CacheStatus, Command, type CommandOptions, CommandRegistry, type CompressionOptions, type CookieMiddlewareOptions, type CorsOptions, type CronSchedule, type CronScheduleParams, CronService, type CronUIOptions, CustomAdapter, type CustomQueueConfiguration, type CustomStorageProviderOptions, CustomTypedQueue, type CustomValidationError, DEFAULT_CACHE_OPTIONS, EdgeAdapter, EjsAdapter, type ExtractParams, GraphQL, type GraphQLContext, type GraphQLOptions, type GraphQLResolverFunction, type GraphQLResolverMap, type GraphQLResolverType, type GraphQLResolvers, type GraphQLSchemaInput, type GraphQLTypeDef, type GroupRouter, HandlebarsAdapter, type HelmetOptions, type HttpMethod, type HttpsOptions, type InferMiddlewareExtension, type InferMiddlewareExtensions, type InferResponseMap, type InferSchemaType, LocalStorageProvider, type LocalStorageProviderOptions, type LockBehavior, type LogOptions, type LoggerOptions, type MailOptions, MailOptionsBuilder, MailProvider, type MailProviderInterface, Mailer, type MailerInterface, type MailerOptions, type MailerProviderOptions, MemoryCacheProvider, MemoryPubSub, type MethodOverrideOptions, MockResponse, MockServer, type MockServerOptions, type MqttConnectionOptions, type MqttHandler, type MqttPublishOptions, MqttService, type MqttSubscribeOptions, type MqttSubscription, type MqttTopics, MustacheAdapter, type NextFunction, type NodeHttpClient, type NodeServer as NodeHttpServerClient, PGBossConfiguration, type PGBossConfigurationOptions, PGBossPubSub, type PolicyDecorator, type PolicyErrorHandlerOptions, PolicyManager, type PolicyProvider, type PolicyRouteConfig, type PublishTopic, QueueManager, QueueService, type RateLimiterKeyOptions, RedisCacheProvider, Request, type RequestSchema, Response$1 as Response, type ResponseBodyForStatus, type RuntimeServer, S3StorageProvider, type S3StorageProviderOptions, SQSConfiguration, type SQSConfigurationOptions, SQSPubSub, type CacheMetrics as SchemaCacheMetrics, type SerializeOptions, type SerializedValidationError, Server, type ServerConnectInput, type ServerErrorHandler, type ServerHook, type ServerInterface, type ServerListenCallback, type ServerOptions, type ServerPlugin, type ServerPluginConfig, type ServerRouteHandler, type ServerRouteMiddleware, type ServerTapOptions, type SessionOptions, type SignalEvent, type StandardMethodOptions, type StaticPluginOptions, Storage, type StorageInterface, type StorageOptions, type StorageProviderOptions, type TemplateMailOptions, type TimeoutOptions, type TrustProxyOptions, type TypedCacheKeyIncludes, type TypedCacheRouteConfig, type TypedHandler, type TypedMiddleware, TypedQueue, type TypedRouteMetadata, type ValidatedData, type ValidationErrorHandlerOptions, type ValidationOptions, arg, asyncLocalStorage, asyncStorage, bullmqQueue, cache, cacheMiddleware, clearAllCaches as clearAllSchemaCaches, commandRegistry, compression, controller, cookie, cors, createExpressAdapter, createPolicyDecorator, createQueue, cron, cronUIInstance, cronUi, Server as default, defineMiddleware, defineQueueConfiguration, del, expressHandler, expressMiddleware, flag, get, getCacheService, getCacheMetrics as getSchemaCacheMetrics, hash, helmet, initCacheService, log, logCacheMetrics as logSchemaCacheMetrics, logger, memoryQueue, methodOverride, middleware, mountExpressRouter, mqtt, patch, pgbossQueue, post, put, rateLimiter, resetCacheService, router, serialize, serveStatic, session, setCronGlobalErrorHandler, setMqttGlobalErrorHandler, sqsQueue, timeout as timeoutMw, trustProxy, validate };
5016
+ export { type AsyncLocalStorageContextSetters, AzureBlobStorageProvider, BaseCron, BasePlugin, type BaseStorageProviderOptions, type BlobStorageProviderOptions, type BodyParserOptions, type BodylessMethodOptions, BullMQConfiguration, type BullMQConfigurationOptions, BullMQPubSub, CACHE_STATUS_HEADER, type CacheKeyIncludes, type CacheMiddlewareOptions, type CachePluginOptions, type CacheProvider, type CacheRedisOptions, type CacheRouteConfig, CacheService, type CacheServiceInterface, type CacheStats, CacheStatus, Command, type CommandOptions, CommandRegistry, type CompressionOptions, type CookieMiddlewareOptions, type CorsOptions, type CronSchedule, type CronScheduleParams, CronService, type CronUIOptions, CustomAdapter, type CustomQueueConfiguration, type CustomStorageProviderOptions, CustomTypedQueue, type CustomValidationError, DEFAULT_CACHE_OPTIONS, EdgeAdapter, EjsAdapter, type ExtractParams, GraphQL, type GraphQLContext, type GraphQLOptions, type GraphQLResolverFunction, type GraphQLResolverMap, type GraphQLResolverType, type GraphQLResolvers, type GraphQLSchemaInput, type GraphQLTypeDef, type GroupRouter, HandlebarsAdapter, type HelmetOptions, type HttpMethod, type HttpsOptions, type InferMiddlewareExtension, type InferMiddlewareExtensions, type InferResponseMap, type InferSchemaType, type InjectFunction, LocalStorageProvider, type LocalStorageProviderOptions, type LockBehavior, type LogOptions, type LoggerOptions, type MailOptions, MailOptionsBuilder, MailProvider, type MailProviderInterface, Mailer, type MailerInterface, type MailerOptions, type MailerProviderOptions, MemoryCacheProvider, MemoryPubSub, type MethodOverrideOptions, MockResponse, MockServer, type MockServerOptions, type MqttConnectionOptions, type MqttHandler, type MqttPublishOptions, MqttService, type MqttSubscribeOptions, type MqttSubscription, type MqttTopics, MustacheAdapter, type NextFunction, type NodeHttpClient, type NodeServer as NodeHttpServerClient, PGBossConfiguration, type PGBossConfigurationOptions, PGBossPubSub, type PolicyDecorator, type PolicyErrorHandlerOptions, PolicyManager, type PolicyProvider, type PolicyRouteConfig, type PublishTopic, QueueManager, QueueService, type RateLimiterKeyOptions, RedisCacheProvider, Request, type RequestSchema, Response$1 as Response, type ResponseBodyForStatus, type RuntimeServer, S3StorageProvider, type S3StorageProviderOptions, SQSConfiguration, type SQSConfigurationOptions, SQSPubSub, type CacheMetrics as SchemaCacheMetrics, type SerializeOptions, type SerializedValidationError, Server, type ServerConnectInput, type ServerErrorHandler, type ServerHook, type ServerInterface, type ServerListenCallback, type ServerOptions, type ServerPlugin, type ServerPluginConfig, type ServerRouteHandler, type ServerRouteMiddleware, type ServerTapOptions, type SessionOptions, type SignalEvent, type StandardMethodOptions, type StaticPluginOptions, Storage, type StorageInterface, type StorageOptions, type StorageProviderOptions, type TemplateMailOptions, type TimeoutOptions, type TrustProxyOptions, type TypedCacheKeyIncludes, type TypedCacheRouteConfig, type TypedHandler, type TypedMiddleware, TypedQueue, type TypedRouteMetadata, type ValidatedData, type ValidationErrorHandlerOptions, type ValidationOptions, arg, asyncLocalStorage, asyncStorage, bodyParser, bullmqQueue, cache, cacheMiddleware, clearAllCaches as clearAllSchemaCaches, commandRegistry, compression, controller, cookie, cors, createExpressAdapter, createPolicyDecorator, createQueue, cron, cronUIInstance, cronUi, Server as default, defineMiddleware, defineQueueConfiguration, del, expressHandler, expressMiddleware, flag, get, getCacheService, getCacheMetrics as getSchemaCacheMetrics, hash, helmet, initCacheService, log, logCacheMetrics as logSchemaCacheMetrics, logger, memoryQueue, methodOverride, middleware, mountExpressRouter, mqtt, patch, pgbossQueue, post, put, rateLimiter, resetCacheService, router, serialize, serveStatic, session, setCronGlobalErrorHandler, setMqttGlobalErrorHandler, sqsQueue, timeout as timeoutMw, trustProxy, validate };