balda 0.0.9 → 0.0.10

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.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { schedule, TaskContext } from 'node-cron';
2
- import { ZodType, ZodAny } from 'zod';
2
+ import { ZodType, z } from 'zod';
3
+ import { TSchema, Static } from '@sinclair/typebox';
3
4
  import { Ajv } from 'ajv';
4
5
  import { ServerResponse, IncomingMessage, Server as Server$2 } from 'node:http';
5
6
  import { Http2Server } from 'node:http2';
@@ -11,7 +12,6 @@ import { RequestHandler, Router as Router$1, IRouter } from 'express';
11
12
  export { ErrorRequestHandler as ExpressErrorMiddleware, RequestHandler as ExpressMiddleware, NextFunction as ExpressNextFunction, Request as ExpressRequest, Response as ExpressResponse } from 'express';
12
13
  import * as pino from 'pino';
13
14
  import pino__default, { pino as pino$1 } from 'pino';
14
- import { TSchema } from '@sinclair/typebox';
15
15
  import { IClientSubscribeOptions, IClientOptions, IClientPublishOptions, MqttClient } from 'mqtt';
16
16
  import { SQSClientConfig, SendMessageCommandInput } from '@aws-sdk/client-sqs';
17
17
  import { Queue, JobsOptions, Job } from 'bullmq';
@@ -301,14 +301,11 @@ type OpenIdConnectOptions = {
301
301
  */
302
302
  declare const controller: (path?: string, swaggerOptions?: SwaggerRouteOptions) => (target: any) => void;
303
303
 
304
- type AjvInstance = InstanceType<typeof Ajv>;
305
- type AjvCompileParams = Parameters<AjvInstance["compile"]>;
306
-
307
304
  type SyncOrAsync<T = void> = T | Promise<T>;
308
305
 
309
306
  interface AsyncLocalStorageContext {
310
307
  }
311
- type AsyncLocalStorageContextSetters<K extends keyof AsyncLocalStorageContext = keyof AsyncLocalStorageContext> = Record<K, (req: Request$1) => SyncOrAsync<AsyncLocalStorageContext[K]>>;
308
+ type AsyncLocalStorageContextSetters<K extends keyof AsyncLocalStorageContext = keyof AsyncLocalStorageContext> = Record<K, (req: Request) => SyncOrAsync<AsyncLocalStorageContext[K]>>;
312
309
 
313
310
  type StaticPluginOptions = {
314
311
  /**
@@ -367,13 +364,33 @@ type FilePluginOptions = {
367
364
  allowedMimeTypes?: (FileAllowedMimeType | (string & {}))[];
368
365
  };
369
366
 
370
- declare global {
371
- interface Request {
372
- params: Record<string, string>;
373
- query: Record<string, string>;
374
- }
367
+ type AjvInstance = InstanceType<typeof Ajv>;
368
+ type AjvCompileParams = Parameters<AjvInstance["compile"]>;
369
+
370
+ type RequestSchema = ZodType | TSchema | AjvCompileParams[0];
371
+ type ValidatedData<T extends RequestSchema> = T extends ZodType ? z.infer<T> : T extends TSchema ? Static<T> : T extends AjvCompileParams[0] ? any : any;
372
+ interface CustomValidationError {
373
+ status?: number;
374
+ message?: string;
375
375
  }
376
- declare class NativeRequest extends Request {
376
+ interface ValidationOptions {
377
+ /**
378
+ * The schema to validate the request body against (Zod, TypeBox, or plain JSON schema)
379
+ */
380
+ body?: RequestSchema;
381
+ /**
382
+ * The schema to validate the query parameters against (Zod, TypeBox, or plain JSON schema)
383
+ */
384
+ query?: RequestSchema;
385
+ /**
386
+ * The schema to validate both body and query against (Zod, TypeBox, or plain JSON schema)
387
+ */
388
+ all?: RequestSchema;
389
+ /**
390
+ * Whether to use safe validation (returns original data if validation fails instead of throwing)
391
+ * @default false
392
+ */
393
+ safe?: boolean;
377
394
  }
378
395
 
379
396
  /**
@@ -382,13 +399,31 @@ declare class NativeRequest extends Request {
382
399
  * It contains the request body, query parameters, files, cookies, etc.
383
400
  * It also contains the validation methods.
384
401
  */
385
- declare class Request$1<Params extends Record<string, string> = any> extends NativeRequest {
386
- static fromRequest(request: Request$1 | NativeRequest): Request$1;
402
+ declare class Request<Params extends Record<string, string> = any> extends globalThis.Request {
403
+ /**
404
+ * Creates a new request object from a Web API Request object.
405
+ * @param request - The Web API Request object to create a new request object from.
406
+ * @returns The new request object.
407
+ */
408
+ static fromRequest(request: globalThis.Request): Request;
409
+ /**
410
+ * Compiles and validates the request data against the input schema.
411
+ * @param inputSchema - The schema to validate the request data against (Zod, TypeBox, or plain JSON schema).
412
+ * @param data - The request data to validate.
413
+ * @param safe - If true, the function will return the original data if the validation fails instead of throwing an error.
414
+ * @returns The validated data.
415
+ */
387
416
  private static compileAndValidate;
388
417
  /**
389
- * Enrich native request with validation methods.
418
+ * The raw Web API Request body.
419
+ * @warning if using body parser middleware, this property will be read and the parsed body will be set to the `parsedBody` property.
420
+ * @warning this body can be read once so be careful not to use it after the body parser middleware has been applied.
421
+ */
422
+ readonly body: globalThis.Request["body"];
423
+ /**
424
+ * The parsed body of the request from the body parser middleware.
390
425
  */
391
- static enrichRequest(request: Request$1): Request$1;
426
+ parsedBody: any;
392
427
  /**
393
428
  * The context of the request. Can be augmented extending AsyncLocalStorageContext interface
394
429
  * @asyncLocalStorage middleware is required
@@ -460,38 +495,30 @@ declare class Request$1<Params extends Record<string, string> = any> extends Nat
460
495
  * The query parameters of the request.
461
496
  */
462
497
  query: Record<string, string>;
463
- /**
464
- * The raw body of the request. Only available for POST, PUT, PATCH and DELETE requests.
465
- */
466
- rawBody?: ArrayBuffer;
467
498
  private _id;
468
499
  /**
469
500
  * The id of the request.
470
501
  */
471
502
  get id(): string;
472
503
  set id(value: string);
473
- /**
474
- * The parsed body of the request
475
- */
476
- body: any;
477
504
  /**
478
505
  * The validated body of the request.
479
506
  * @param inputSchema - The schema to validate the body against (Zod schema or JSON Schema).
480
507
  * @param safe - If true, the function will return the original body if the validation fails instead of throwing an error.
481
508
  */
482
- validate(inputSchema: ZodAny | AjvCompileParams[0], safe?: boolean): any;
509
+ validate<T extends RequestSchema>(inputSchema: T, safe?: boolean): ValidatedData<T>;
483
510
  /**
484
511
  * Validates the query string of the request.
485
512
  * @param inputSchema - The schema to validate the query against (Zod schema or JSON Schema).
486
513
  * @param safe - If true, the function will return undefined if the validation fails instead of throwing an error.
487
514
  */
488
- validateQuery(inputSchema: ZodAny | AjvCompileParams[0], safe?: boolean): any;
515
+ validateQuery<T extends RequestSchema>(inputSchema: T, safe?: boolean): ValidatedData<T>;
489
516
  /**
490
517
  * Validates the body and query string of the request.
491
518
  * @param inputSchema - The schema to validate against (Zod schema or JSON Schema).
492
519
  * @param safe - If true, the function will return undefined if the validation fails instead of throwing an error.
493
520
  */
494
- validateAll(inputSchema: ZodAny | AjvCompileParams[0], safe?: boolean): any;
521
+ validateAll<T extends RequestSchema>(inputSchema: T, safe?: boolean): ValidatedData<T>;
495
522
  }
496
523
 
497
524
  /**
@@ -790,7 +817,7 @@ declare class Response$1 {
790
817
  getBody(): any;
791
818
  }
792
819
 
793
- type DelHandler = (req: Request$1, res: Response$1, ...args: any[]) => any;
820
+ type DelHandler = (req: Request, res: Response$1, ...args: any[]) => any;
794
821
  /**
795
822
  * Decorator to mark an handler for a DELETE request
796
823
  * @param path - The path of the route
@@ -811,7 +838,7 @@ type DelHandler = (req: Request$1, res: Response$1, ...args: any[]) => any;
811
838
  */
812
839
  declare const del: (path: string, options?: SwaggerRouteOptions) => <T extends DelHandler>(target: any, propertyKey: string, descriptor: PropertyDescriptor) => TypedPropertyDescriptor<T>;
813
840
 
814
- type GetHandler = (req: Request$1, res: Response$1, ...args: any[]) => any;
841
+ type GetHandler = (req: Request, res: Response$1, ...args: any[]) => any;
815
842
  /**
816
843
  * Decorator to mark an handler for a GET request
817
844
  * @param path - The path of the route
@@ -832,7 +859,7 @@ type GetHandler = (req: Request$1, res: Response$1, ...args: any[]) => any;
832
859
  */
833
860
  declare const get: (path: string, options?: SwaggerRouteOptions) => <T extends GetHandler>(target: any, propertyKey: string, descriptor: PropertyDescriptor) => TypedPropertyDescriptor<T>;
834
861
 
835
- type PatchHandler = (req: Request$1, res: Response$1, ...args: any[]) => any;
862
+ type PatchHandler = (req: Request, res: Response$1, ...args: any[]) => any;
836
863
  /**
837
864
  * Decorator to mark an handler for a PATCH request
838
865
  * @param path - The path of the route
@@ -853,7 +880,7 @@ type PatchHandler = (req: Request$1, res: Response$1, ...args: any[]) => any;
853
880
  */
854
881
  declare const patch: (path: string, options?: SwaggerRouteOptions) => <T extends PatchHandler>(target: any, propertyKey: string, descriptor: PropertyDescriptor) => TypedPropertyDescriptor<T>;
855
882
 
856
- type PostHandler = (req: Request$1, res: Response$1, ...args: any[]) => any;
883
+ type PostHandler = (req: Request, res: Response$1, ...args: any[]) => any;
857
884
  /**
858
885
  * Decorator to mark an handler for a POST request
859
886
  * @param path - The path of the route
@@ -874,7 +901,7 @@ type PostHandler = (req: Request$1, res: Response$1, ...args: any[]) => any;
874
901
  */
875
902
  declare const post: (path: string, options?: SwaggerRouteOptions) => <T extends PostHandler>(target: any, propertyKey: string, descriptor: PropertyDescriptor) => TypedPropertyDescriptor<T>;
876
903
 
877
- type PutHandler = (req: Request$1, res: Response$1, ...args: any[]) => any;
904
+ type PutHandler = (req: Request, res: Response$1, ...args: any[]) => any;
878
905
  /**
879
906
  * Decorator to mark an handler for a PUT request
880
907
  * @param path - The path of the route
@@ -1318,38 +1345,6 @@ interface HelmetOptions {
1318
1345
  contentSecurityPolicy?: false | string;
1319
1346
  }
1320
1347
 
1321
- interface JsonOptions {
1322
- /**
1323
- * The maximum size of the JSON body in bytes.
1324
- * If the body is larger than this limit, the request will be rejected.
1325
- * Default: 100kb
1326
- */
1327
- sizeLimit?: `${number}mb` | `${number}kb`;
1328
- /**
1329
- * If true, the JSON body will be parsed as an empty object if it is empty.
1330
- * Default: false (body will be undefined)
1331
- */
1332
- parseEmptyBodyAsObject?: boolean;
1333
- /**
1334
- * The encoding to use when decoding the request body.
1335
- * Default: "utf-8"
1336
- */
1337
- encoding?: TextDecoderEncoding;
1338
- /**
1339
- * The custom error message to return when the JSON body is too large.
1340
- * Default: response with status 413 and body { message: "ERR_REQUEST_BODY_TOO_LARGE" }
1341
- */
1342
- customErrorMessage?: {
1343
- status?: number;
1344
- message?: string;
1345
- };
1346
- }
1347
- /**
1348
- * Supported text encodings for TextDecoder.
1349
- * Based on the WHATWG Encoding Standard.
1350
- */
1351
- type TextDecoderEncoding = "utf-8" | "utf-16le" | "utf-16be" | "gbk" | "gb18030" | "big5" | "euc-jp" | "iso-2022-jp" | "shift-jis" | "euc-kr" | "iso-2022-kr" | "iso-8859-1" | "iso-8859-2" | "iso-8859-3" | "iso-8859-4" | "iso-8859-5" | "iso-8859-6" | "iso-8859-7" | "iso-8859-8" | "iso-8859-9" | "iso-8859-10" | "iso-8859-13" | "iso-8859-14" | "iso-8859-15" | "iso-8859-16" | "windows-1250" | "windows-1251" | "windows-1252" | "windows-1253" | "windows-1254" | "windows-1255" | "windows-1256" | "windows-1257" | "windows-1258" | "x-mac-cyrillic" | "x-mac-greek" | "x-mac-icelandic" | "x-mac-latin2" | "x-mac-roman" | "x-mac-turkish" | "koi8-r" | "koi8-u";
1352
-
1353
1348
  type LoggerOptions = Parameters<typeof pino$1>[0];
1354
1349
 
1355
1350
  interface LogOptions {
@@ -1444,7 +1439,7 @@ type CustomRateLimiterOptions = {
1444
1439
  /**
1445
1440
  * Generate a key for the rate limiter from the request (e.g. user id, email, etc.)
1446
1441
  */
1447
- key: (req: Request$1) => string;
1442
+ key: (req: Request) => string;
1448
1443
  /**
1449
1444
  * The storage strategy to use
1450
1445
  * @default "memory"
@@ -1533,6 +1528,35 @@ type TrustProxyOptions = {
1533
1528
  hop?: "first" | "last";
1534
1529
  };
1535
1530
 
1531
+ /**
1532
+ * The next function.
1533
+ * This is the function that is passed to the handler function.
1534
+ * It has a pointer to the next middleware or handler function of the middleware chain.
1535
+ */
1536
+ type NextFunction = () => SyncOrAsync;
1537
+
1538
+ interface JsonOptions {
1539
+ /**
1540
+ * The maximum size of the JSON body in bytes.
1541
+ * If the body is larger than this limit, the request will be rejected.
1542
+ * Default: 100kb
1543
+ */
1544
+ sizeLimit?: `${number}mb` | `${number}kb`;
1545
+ /**
1546
+ * If true, the JSON body will be parsed as an empty object if it is empty.
1547
+ * Default: false (body will be undefined)
1548
+ */
1549
+ parseEmptyBodyAsObject?: boolean;
1550
+ /**
1551
+ * The custom error message to return when the JSON body is too large.
1552
+ * Default: response with status 413 and body { message: "ERR_REQUEST_BODY_TOO_LARGE" }
1553
+ */
1554
+ customErrorMessage?: {
1555
+ status?: number;
1556
+ message?: string;
1557
+ };
1558
+ }
1559
+
1536
1560
  /**
1537
1561
  * Options for URL-encoded middleware
1538
1562
  */
@@ -1561,22 +1585,19 @@ type UrlEncodedOptions = {
1561
1585
  parameterLimit?: number;
1562
1586
  };
1563
1587
 
1564
- /**
1565
- * The next function.
1566
- * This is the function that is passed to the handler function.
1567
- * It has a pointer to the next middleware or handler function of the middleware chain.
1568
- */
1569
- type NextFunction = () => SyncOrAsync;
1588
+ type BodyParserOptions = {
1589
+ json?: JsonOptions;
1590
+ urlencoded?: UrlEncodedOptions;
1591
+ fileParser?: FilePluginOptions;
1592
+ };
1570
1593
 
1571
1594
  type ServerPlugin = {
1595
+ bodyParser?: BodyParserOptions;
1572
1596
  cors?: CorsOptions;
1573
- json?: JsonOptions;
1574
1597
  static?: StaticPluginOptions;
1575
- fileParser?: FilePluginOptions;
1576
1598
  helmet?: HelmetOptions;
1577
1599
  cookie?: CookieMiddlewareOptions;
1578
1600
  log?: LogOptions;
1579
- urlencoded?: UrlEncodedOptions;
1580
1601
  rateLimiter?: {
1581
1602
  keyOptions?: RateLimiterKeyOptions;
1582
1603
  storageOptions?: StorageOptions$1;
@@ -1602,8 +1623,6 @@ type ServerOptions<H extends NodeHttpClient = NodeHttpClient> = {
1602
1623
  plugins?: ServerPlugin;
1603
1624
  /** The tap options to interact with the underlying server connector before it is used to listen for incoming requests */
1604
1625
  tapOptions?: ServerTapOptions;
1605
- /** Whether to use the body parser plugin, by default it is true, it is really recommended to use it */
1606
- useBodyParser?: boolean;
1607
1626
  /**
1608
1627
  * The swagger options to apply to the server, by default swagger plugin is applied with standard options, you can pass a boolean to enable or disable the plugin or you can pass an object to apply custom options to the plugin
1609
1628
  * @example
@@ -1651,11 +1670,10 @@ type ResolvedServerOptions = {
1651
1670
  controllerPatterns: string[];
1652
1671
  plugins: ServerPlugin;
1653
1672
  tapOptions: ServerTapOptions;
1654
- useBodyParser: boolean;
1655
1673
  swagger: Parameters<typeof swagger>[0] | boolean;
1656
1674
  graphql?: GraphQLOptions;
1657
1675
  };
1658
- type ServerErrorHandler = (req: Request$1, res: Response$1, next: NextFunction, error: Error) => SyncOrAsync;
1676
+ type ServerErrorHandler = (req: Request, res: Response$1, next: NextFunction, error: Error) => SyncOrAsync;
1659
1677
  interface ServerInterface {
1660
1678
  /**
1661
1679
  * Identifier for the balda server instance
@@ -1932,8 +1950,8 @@ type ServerConnectInput<H extends NodeHttpClient = NodeHttpClient> = {
1932
1950
  /** The graphql options to apply to the server */
1933
1951
  graphql?: GraphQL;
1934
1952
  } & (H extends "https" ? HttpsOptions<H> : {});
1935
- type ServerRouteMiddleware = (req: Request$1, res: Response$1, next: NextFunction) => SyncOrAsync;
1936
- type ServerRouteHandler = (req: Request$1, res: Response$1) => SyncOrAsync;
1953
+ type ServerRouteMiddleware = (req: Request, res: Response$1, next: NextFunction) => SyncOrAsync;
1954
+ type ServerRouteHandler = (req: Request, res: Response$1) => SyncOrAsync;
1937
1955
  interface ServerRoute {
1938
1956
  /** The path for the route */
1939
1957
  path: string;
@@ -1952,7 +1970,7 @@ type ServerListenCallback = ({ port, host, url, }: {
1952
1970
  /**
1953
1971
  * Custom bun fetch call to be used as an hook inside Bun.serve method
1954
1972
  */
1955
- type CustomBunFetch = (req: Request$1, server: Bun.Server<any>) => SyncOrAsync;
1973
+ type CustomBunFetch = (req: Request, server: Bun.Server<any>) => SyncOrAsync;
1956
1974
  /**
1957
1975
  * Custom deno fetch call to be used as an hook inside Deno.serve method
1958
1976
  */
@@ -1998,39 +2016,15 @@ interface SerializeOptions {
1998
2016
  safe?: boolean;
1999
2017
  }
2000
2018
 
2001
- declare const serialize: <T extends ZodType | TSchema | AjvCompileParams[0]>(schema: T, options?: SerializeOptions) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
2002
-
2003
- interface CustomValidationError {
2004
- status?: number;
2005
- message?: string;
2006
- }
2007
- interface ValidationOptions {
2008
- /**
2009
- * The schema to validate the request body against (Zod, TypeBox, or plain JSON schema)
2010
- */
2011
- body?: ZodType | TSchema | AjvCompileParams[0];
2012
- /**
2013
- * The schema to validate the query parameters against (Zod, TypeBox, or plain JSON schema)
2014
- */
2015
- query?: ZodType | TSchema | AjvCompileParams[0];
2016
- /**
2017
- * The schema to validate both body and query against (Zod, TypeBox, or plain JSON schema)
2018
- */
2019
- all?: ZodType | TSchema | AjvCompileParams[0];
2020
- /**
2021
- * Whether to use safe validation (returns original data if validation fails instead of throwing)
2022
- * @default false
2023
- */
2024
- safe?: boolean;
2025
- }
2019
+ declare const serialize: <T extends RequestSchema>(schema: T, options?: SerializeOptions) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
2026
2020
 
2027
2021
  declare const validate: {
2028
2022
  (options: ValidationOptions & {
2029
2023
  customError?: CustomValidationError;
2030
2024
  }): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
2031
- query(schema: ZodType | AjvCompileParams[0], customError?: CustomValidationError): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
2032
- body(schema: ZodType | AjvCompileParams[0], customError?: CustomValidationError): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
2033
- all(schema: ZodType | AjvCompileParams[0], customError?: CustomValidationError): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
2025
+ query(schema: RequestSchema, customError?: CustomValidationError): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
2026
+ body(schema: RequestSchema, customError?: CustomValidationError): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
2027
+ all(schema: RequestSchema, customError?: CustomValidationError): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
2034
2028
  };
2035
2029
 
2036
2030
  /**
@@ -2207,6 +2201,25 @@ declare class BaseQueue {
2207
2201
  protected readonly logger: pino.Logger<string, boolean>;
2208
2202
  }
2209
2203
 
2204
+ declare class BullMQPubSub implements GenericPubSub {
2205
+ private queues;
2206
+ private workers;
2207
+ private bullmqClient;
2208
+ publish<TPayload>(topic: string, payload: TPayload, options?: PublishOptions<"bullmq">): Promise<{
2209
+ id: string;
2210
+ }>;
2211
+ subscribe<TPayload>(topic: string, handler: (payload: TPayload) => Promise<void>): Promise<void>;
2212
+ private getQueue;
2213
+ private getBullMQClient;
2214
+ publishWithConfig<TPayload>(topic: string, payload: TPayload, options?: PublishOptions<"bullmq">, queueConfig?: BullMQQueueOptions): Promise<{
2215
+ id: string;
2216
+ }>;
2217
+ subscribeWithConfig<TPayload>(topic: string, handler: (payload: TPayload) => Promise<void>, queueConfig?: BullMQQueueOptions): Promise<void>;
2218
+ private getQueueWithConfig;
2219
+ private getQueueKey;
2220
+ private getWorkerKey;
2221
+ }
2222
+
2210
2223
  declare class PGBossPubSub implements GenericPubSub {
2211
2224
  private boss;
2212
2225
  private createdQueues;
@@ -2271,141 +2284,6 @@ interface QueueProvider {
2271
2284
  }
2272
2285
  type QueueProviderKey = keyof QueueProvider;
2273
2286
 
2274
- declare class BullMQPubSub implements GenericPubSub {
2275
- private queues;
2276
- private workers;
2277
- private bullmqClient;
2278
- publish<TPayload>(topic: string, payload: TPayload, options?: PublishOptions<"bullmq">): Promise<{
2279
- id: string;
2280
- }>;
2281
- subscribe<TPayload>(topic: string, handler: (payload: TPayload) => Promise<void>): Promise<void>;
2282
- private getQueue;
2283
- private getBullMQClient;
2284
- publishWithConfig<TPayload>(topic: string, payload: TPayload, options?: PublishOptions<"bullmq">, queueConfig?: BullMQQueueOptions): Promise<{
2285
- id: string;
2286
- }>;
2287
- subscribeWithConfig<TPayload>(topic: string, handler: (payload: TPayload) => Promise<void>, queueConfig?: BullMQQueueOptions): Promise<void>;
2288
- private getQueueWithConfig;
2289
- private getQueueKey;
2290
- private getWorkerKey;
2291
- }
2292
-
2293
- /**
2294
- * Options for BullMQ configuration
2295
- * @param options - The options for BullMQ
2296
- * @param errorHandler - Custom error handler that will be triggered when a job fails, for logging or debug purposes
2297
- */
2298
- type BullMQConfigurationOptions = ConstructorParameters<typeof Queue>[1] & {
2299
- errorHandler?: (job: Job, error: Error) => SyncOrAsync;
2300
- };
2301
- declare class BullMQConfiguration {
2302
- static options: BullMQConfigurationOptions;
2303
- }
2304
- /**
2305
- * Define globally custom BullMQ configuration
2306
- * @param options - The BullMQ configuration options
2307
- */
2308
- declare const defineBullMQConfiguration: (options: BullMQConfigurationOptions) => void;
2309
-
2310
- type CustomQueueConfiguration = GenericPubSub;
2311
-
2312
- type PGBossConfigurationOptions = {
2313
- connectionString?: string;
2314
- boss?: unknown;
2315
- errorHandler?: (error: Error) => SyncOrAsync;
2316
- };
2317
- declare class PGBossConfiguration {
2318
- static options: PGBossConfigurationOptions;
2319
- }
2320
- declare const definePGBossConfiguration: (options: PGBossConfigurationOptions) => void;
2321
-
2322
- type SQSConfigurationOptions = {
2323
- client?: SQSClientConfig;
2324
- consumer?: {
2325
- batchSize?: number;
2326
- visibilityTimeout?: number;
2327
- waitTimeSeconds?: number;
2328
- queueUrlMap: Record<string, string>;
2329
- };
2330
- errorHandler?: (error: Error) => SyncOrAsync;
2331
- };
2332
- declare class SQSConfiguration {
2333
- static options: SQSConfigurationOptions;
2334
- }
2335
- declare const defineSQSConfiguration: (options: SQSConfigurationOptions) => void;
2336
-
2337
- declare class QueueManager {
2338
- static map: Map<QueueProviderKey, GenericPubSub>;
2339
- static getProvider<P extends QueueProviderKey>(provider: P): GenericPubSub<P>;
2340
- static setProvider(provider: QueueProviderKey, pubsub: GenericPubSub<QueueProviderKey>): void;
2341
- }
2342
-
2343
- /**
2344
- * Main entry point to define the queue configuration, meant to be called only once in the application bootstrap
2345
- * @bullmq - The BullMQ configuration options
2346
- * @pgboss - The PGBoss configuration options
2347
- * @sqs - The SQS configuration options
2348
- * @string - The custom queue provider name with it's PubSub implementation
2349
- * @example
2350
- * defineQueueConfiguration({
2351
- * bullmq: {
2352
- * connection: {
2353
- * host: "127.0.0.1",
2354
- * password: "root",
2355
- * username: "default",
2356
- * db: 0,
2357
- * },
2358
- * },
2359
- * pgboss: {
2360
- * connectionString: "postgres://root:root@localhost:5432/database",
2361
- * },
2362
- * sqs: {
2363
- * client: { region: "us-east-1" },
2364
- * },
2365
- * custom: new CustomPubSub(),
2366
- * });
2367
- * @example
2368
- * defineQueueConfiguration({
2369
- * custom: new CustomPubSub(),
2370
- * });
2371
- */
2372
- declare const defineQueueConfiguration: (options: {
2373
- bullmq?: Parameters<typeof defineBullMQConfiguration>[0];
2374
- pgboss?: Parameters<typeof definePGBossConfiguration>[0];
2375
- sqs?: Parameters<typeof defineSQSConfiguration>[0];
2376
- } & { [key in Exclude<QueueProviderKey, "bullmq" | "pgboss" | "sqs">]?: CustomQueueConfiguration; }) => void;
2377
-
2378
- type QueueHandler = (payload: unknown) => Promise<void>;
2379
- type TypedQueueRegistration = {
2380
- name: string;
2381
- topic: string;
2382
- handler: QueueHandler;
2383
- provider: BuiltInProviderKey;
2384
- queueOptions?: unknown;
2385
- };
2386
- type CustomQueueRegistration = {
2387
- name: string;
2388
- topic: string;
2389
- handler: QueueHandler;
2390
- pubsub: GenericPubSub;
2391
- };
2392
- declare class QueueService {
2393
- static typedQueueSubscribers: Map<string, TypedQueueRegistration>;
2394
- static customQueueSubscribers: Map<string, CustomQueueRegistration>;
2395
- /**
2396
- * Factory function for creating handler instances.
2397
- * Can be overridden to provide custom dependency injection.
2398
- * @default Creates new instance using constructor
2399
- */
2400
- static instanceFactory: (ctor: Function) => object;
2401
- static registerTypedQueue(name: string, topic: string, handler: QueueHandler, provider: BuiltInProviderKey, queueOptions?: unknown): void;
2402
- static registerCustomQueue(name: string, topic: string, handler: QueueHandler, pubsub: GenericPubSub): void;
2403
- static run(): Promise<void>;
2404
- static massiveImportQueues(queueHandlerPatterns: string[], options?: {
2405
- throwOnError?: boolean;
2406
- }): Promise<void>;
2407
- }
2408
-
2409
2287
  type QueueOptionsForProvider<P extends BuiltInProviderKey> = P extends "sqs" ? SQSQueueOptions : P extends "bullmq" ? BullMQQueueOptions : P extends "pgboss" ? PGBossQueueOptions : never;
2410
2288
  /**
2411
2289
  * TypedQueue for built-in providers (sqs, bullmq, pgboss)
@@ -2556,6 +2434,122 @@ declare function pgbossQueue<TPayload>(topic: string, options?: PGBossQueueOptio
2556
2434
  */
2557
2435
  declare function createQueue<TPayload, TOptions = Record<string, unknown>>(topic: string, pubsub: GenericPubSub<TPayload>): CustomTypedQueue<TPayload, TOptions>;
2558
2436
 
2437
+ /**
2438
+ * Options for BullMQ configuration
2439
+ * @param options - The options for BullMQ
2440
+ * @param errorHandler - Custom error handler that will be triggered when a job fails, for logging or debug purposes
2441
+ */
2442
+ type BullMQConfigurationOptions = ConstructorParameters<typeof Queue>[1] & {
2443
+ errorHandler?: (job: Job, error: Error) => SyncOrAsync;
2444
+ };
2445
+ declare class BullMQConfiguration {
2446
+ static options: BullMQConfigurationOptions;
2447
+ }
2448
+ /**
2449
+ * Define globally custom BullMQ configuration
2450
+ * @param options - The BullMQ configuration options
2451
+ */
2452
+ declare const defineBullMQConfiguration: (options: BullMQConfigurationOptions) => void;
2453
+
2454
+ type CustomQueueConfiguration = GenericPubSub;
2455
+
2456
+ type PGBossConfigurationOptions = {
2457
+ connectionString?: string;
2458
+ boss?: unknown;
2459
+ errorHandler?: (error: Error) => SyncOrAsync;
2460
+ };
2461
+ declare class PGBossConfiguration {
2462
+ static options: PGBossConfigurationOptions;
2463
+ }
2464
+ declare const definePGBossConfiguration: (options: PGBossConfigurationOptions) => void;
2465
+
2466
+ type SQSConfigurationOptions = {
2467
+ client?: SQSClientConfig;
2468
+ consumer?: {
2469
+ batchSize?: number;
2470
+ visibilityTimeout?: number;
2471
+ waitTimeSeconds?: number;
2472
+ queueUrlMap: Record<string, string>;
2473
+ };
2474
+ errorHandler?: (error: Error) => SyncOrAsync;
2475
+ };
2476
+ declare class SQSConfiguration {
2477
+ static options: SQSConfigurationOptions;
2478
+ }
2479
+ declare const defineSQSConfiguration: (options: SQSConfigurationOptions) => void;
2480
+
2481
+ declare class QueueManager {
2482
+ static map: Map<QueueProviderKey, GenericPubSub>;
2483
+ static getProvider<P extends QueueProviderKey>(provider: P): GenericPubSub<P>;
2484
+ static setProvider(provider: QueueProviderKey, pubsub: GenericPubSub<QueueProviderKey>): void;
2485
+ }
2486
+
2487
+ /**
2488
+ * Main entry point to define the queue configuration, meant to be called only once in the application bootstrap
2489
+ * @bullmq - The BullMQ configuration options
2490
+ * @pgboss - The PGBoss configuration options
2491
+ * @sqs - The SQS configuration options
2492
+ * @string - The custom queue provider name with it's PubSub implementation
2493
+ * @example
2494
+ * defineQueueConfiguration({
2495
+ * bullmq: {
2496
+ * connection: {
2497
+ * host: "127.0.0.1",
2498
+ * password: "root",
2499
+ * username: "default",
2500
+ * db: 0,
2501
+ * },
2502
+ * },
2503
+ * pgboss: {
2504
+ * connectionString: "postgres://root:root@localhost:5432/database",
2505
+ * },
2506
+ * sqs: {
2507
+ * client: { region: "us-east-1" },
2508
+ * },
2509
+ * custom: new CustomPubSub(),
2510
+ * });
2511
+ * @example
2512
+ * defineQueueConfiguration({
2513
+ * custom: new CustomPubSub(),
2514
+ * });
2515
+ */
2516
+ declare const defineQueueConfiguration: (options: {
2517
+ bullmq?: Parameters<typeof defineBullMQConfiguration>[0];
2518
+ pgboss?: Parameters<typeof definePGBossConfiguration>[0];
2519
+ sqs?: Parameters<typeof defineSQSConfiguration>[0];
2520
+ } & { [key in Exclude<QueueProviderKey, "bullmq" | "pgboss" | "sqs">]?: CustomQueueConfiguration; }) => void;
2521
+
2522
+ type QueueHandler = (payload: unknown) => Promise<void>;
2523
+ type TypedQueueRegistration = {
2524
+ name: string;
2525
+ topic: string;
2526
+ handler: QueueHandler;
2527
+ provider: BuiltInProviderKey;
2528
+ queueOptions?: unknown;
2529
+ };
2530
+ type CustomQueueRegistration = {
2531
+ name: string;
2532
+ topic: string;
2533
+ handler: QueueHandler;
2534
+ pubsub: GenericPubSub;
2535
+ };
2536
+ declare class QueueService {
2537
+ static typedQueueSubscribers: Map<string, TypedQueueRegistration>;
2538
+ static customQueueSubscribers: Map<string, CustomQueueRegistration>;
2539
+ /**
2540
+ * Factory function for creating handler instances.
2541
+ * Can be overridden to provide custom dependency injection.
2542
+ * @default Creates new instance using constructor
2543
+ */
2544
+ static instanceFactory: (ctor: Function) => object;
2545
+ static registerTypedQueue(name: string, topic: string, handler: QueueHandler, provider: BuiltInProviderKey, queueOptions?: unknown): void;
2546
+ static registerCustomQueue(name: string, topic: string, handler: QueueHandler, pubsub: GenericPubSub): void;
2547
+ static run(): Promise<void>;
2548
+ static massiveImportQueues(queueHandlerPatterns: string[], options?: {
2549
+ throwOnError?: boolean;
2550
+ }): Promise<void>;
2551
+ }
2552
+
2559
2553
  /**
2560
2554
  * The logger instance, can be overridden by the `defineLoggerConfig` function
2561
2555
  */
@@ -3167,30 +3161,12 @@ declare function createExpressAdapter(server: {
3167
3161
  use(pathOrMiddleware: string | RequestHandler | Router$1, maybeMiddleware?: RequestHandler | Router$1): void;
3168
3162
  };
3169
3163
 
3170
- /**
3171
- * Middleware to handle multipart/form-data file uploads with security validations.
3172
- * - Validates files against `FilePluginOptions`: size limits, file count, MIME types.
3173
- * - Sanitizes filenames to prevent path traversal attacks.
3174
- * - Uses cryptographically secure random filenames (UUID) in temporary storage.
3175
- * - Stores uploaded files in a runtime-agnostic temporary directory and exposes them via `req.files`.
3176
- * - Automatically cleans up temporary files after request completion or on error.
3177
- * - Can be used as global middleware or route-specific middleware.
3178
- */
3179
- declare const fileParser: (options?: FilePluginOptions) => ServerRouteMiddleware;
3180
-
3181
3164
  /**
3182
3165
  * Sets common HTTP security headers
3183
3166
  * @param options Helmet options (all optional)
3184
3167
  */
3185
3168
  declare const helmet: (options?: HelmetOptions) => ServerRouteMiddleware;
3186
3169
 
3187
- /**
3188
- * Middleware to parse the JSON body of the request. GET, DELETE and OPTIONS requests are not parsed.
3189
- * @param options - The options for the JSON middleware.
3190
- * @param options.sizeLimit - The maximum size of the JSON body. Default: 100kb
3191
- */
3192
- declare const json: (options?: JsonOptions) => ServerRouteMiddleware;
3193
-
3194
3170
  /**
3195
3171
  * Logs the request and response of the handler, can be set both on a specific route or on a global middleware.
3196
3172
  * @warning Only json objects and strings are logged from the request and response.
@@ -3259,18 +3235,6 @@ declare const timeout: (options: TimeoutOptions) => ServerRouteMiddleware;
3259
3235
  */
3260
3236
  declare const trustProxy: (options?: TrustProxyOptions) => ServerRouteMiddleware;
3261
3237
 
3262
- /**
3263
- * URL-encoded form data parser middleware
3264
- * Parses application/x-www-form-urlencoded bodies and populates req.body
3265
- * @param options URL-encoded parsing options
3266
- * @param options.limit The maximum size of the URL-encoded body. Supports "5mb", "100kb" format. Defaults to "1mb".
3267
- * @param options.extended Whether to parse extended syntax (objects and arrays). Defaults to false.
3268
- * @param options.charset The character encoding to use when parsing. Defaults to 'utf8'.
3269
- * @param options.allowEmpty Whether to allow empty values. Defaults to true.
3270
- * @param options.parameterLimit Maximum number of parameters to parse. Defaults to 1000.
3271
- */
3272
- declare const urlencoded: (options?: UrlEncodedOptions) => ServerRouteMiddleware;
3273
-
3274
3238
  type PolicyProvider = {
3275
3239
  [K: string]: (...args: any[]) => Promise<boolean> | boolean;
3276
3240
  };
@@ -3304,4 +3268,4 @@ declare const createPolicyDecorator: <T extends Record<string, PolicyProvider>>(
3304
3268
  */
3305
3269
  declare const router: ClientRouter;
3306
3270
 
3307
- export { ARG_SYMBOL, AzureBlobStorageProvider, BaseCron, BaseMqtt, BasePlugin, BaseQueue, type BaseStorageProviderOptions, type BlobStorageProviderOptions, BullMQConfiguration, type BullMQConfigurationOptions, BullMQPubSub, type BunTapOptions, Command, type CommandOptions, CommandRegistry, type CronSchedule, type CronScheduleParams, CronService, type CustomQueueConfiguration, type CustomStorageProviderOptions, CustomTypedQueue, type CustomValidationError, type DenoTapOptions, type ExpressAdapterOptions, type ExpressHandler, type ExpressRouter, type FileAllowedMimeType, GraphQL, type GraphQLContext, type GraphQLOptions, type GraphQLResolverFunction, type GraphQLResolverMap, type GraphQLResolverType, type GraphQLResolvers, type GraphQLSchemaInput, type GraphQLTypeDef, type HttpMethod, type HttpsOptions, LocalStorageProvider, type LocalStorageProviderOptions, type LoggerOptions, MockServer, type MockServerOptions, type MqttConnectionOptions, type MqttHandler, type MqttPublishOptions, MqttService, type MqttSubscribeOptions, type MqttSubscription, type MqttTopics, type NextFunction, type NodeHttpClient, type NodeServer, type NodeTapOptions, PGBossConfiguration, type PGBossConfigurationOptions, PGBossPubSub, type PolicyDecorator, PolicyManager, type PolicyMetadata, type PolicyProvider, QueueManager, QueueService, Request$1 as Request, type ResolvedServerOptions, Response$1 as Response, type ReturnType$1 as ReturnType, type ReturnTypeMap, type RuntimeServer, type RuntimeServerMap, S3StorageProvider, type S3StorageProviderOptions, SQSConfiguration, type SQSConfigurationOptions, SQSPubSub, type SerializeOptions, Server, type ServerConnectInput, type ServerErrorHandler, type ServerInterface, type ServerListenCallback, type ServerOptions, type ServerPlugin, type ServerRoute, type ServerRouteHandler, type ServerRouteMiddleware, type ServerTapOptions, type ServerTapOptionsBuilder, type SignalEvent, type StandardMethodOptions, type StaticPluginOptions, Storage, type StorageInterface, type StorageOptions, type StorageProviderOptions, TypedQueue, VALIDATION_ERROR_SYMBOL, type ValidationOptions, arg, asyncLocalStorage, asyncStorage, baseCommands, bullmqQueue, commandRegistry, compression, controller, cookie, cors, createExpressAdapter, createPolicyDecorator, createQueue, cron, defineLoggerConfig, defineQueueConfiguration, del, expressHandler, expressMiddleware, fileParser, flag, get, getContentType, hash, helmet, json, log, logger, methodOverride, middleware, mountExpressRouter, mqtt, patch, pgbossQueue, post, put, rateLimiter, router, serialize, serveStatic, session, setCronGlobalErrorHandler, setMqttGlobalErrorHandler, sqsQueue, timeout, trustProxy, urlencoded, validate };
3271
+ export { ARG_SYMBOL, AzureBlobStorageProvider, BaseCron, BaseMqtt, BasePlugin, BaseQueue, type BaseStorageProviderOptions, type BlobStorageProviderOptions, BullMQConfiguration, type BullMQConfigurationOptions, BullMQPubSub, type BunTapOptions, Command, type CommandOptions, CommandRegistry, type CronSchedule, type CronScheduleParams, CronService, type CustomQueueConfiguration, type CustomStorageProviderOptions, CustomTypedQueue, type CustomValidationError, type DenoTapOptions, type ExpressAdapterOptions, type ExpressHandler, type ExpressRouter, type FileAllowedMimeType, GraphQL, type GraphQLContext, type GraphQLOptions, type GraphQLResolverFunction, type GraphQLResolverMap, type GraphQLResolverType, type GraphQLResolvers, type GraphQLSchemaInput, type GraphQLTypeDef, type HttpMethod, type HttpsOptions, LocalStorageProvider, type LocalStorageProviderOptions, type LoggerOptions, MockServer, type MockServerOptions, type MqttConnectionOptions, type MqttHandler, type MqttPublishOptions, MqttService, type MqttSubscribeOptions, type MqttSubscription, type MqttTopics, type NextFunction, type NodeHttpClient, type NodeServer, type NodeTapOptions, PGBossConfiguration, type PGBossConfigurationOptions, PGBossPubSub, type PolicyDecorator, PolicyManager, type PolicyMetadata, type PolicyProvider, QueueManager, QueueService, Request, type RequestSchema, type ResolvedServerOptions, Response$1 as Response, type ReturnType$1 as ReturnType, type ReturnTypeMap, type RuntimeServer, type RuntimeServerMap, S3StorageProvider, type S3StorageProviderOptions, SQSConfiguration, type SQSConfigurationOptions, SQSPubSub, type SerializeOptions, Server, type ServerConnectInput, type ServerErrorHandler, type ServerInterface, type ServerListenCallback, type ServerOptions, type ServerPlugin, type ServerRoute, type ServerRouteHandler, type ServerRouteMiddleware, type ServerTapOptions, type ServerTapOptionsBuilder, type SignalEvent, type StandardMethodOptions, type StaticPluginOptions, Storage, type StorageInterface, type StorageOptions, type StorageProviderOptions, TypedQueue, VALIDATION_ERROR_SYMBOL, type ValidatedData, type ValidationOptions, arg, asyncLocalStorage, asyncStorage, baseCommands, bullmqQueue, commandRegistry, compression, controller, cookie, cors, createExpressAdapter, createPolicyDecorator, createQueue, cron, defineLoggerConfig, defineQueueConfiguration, del, expressHandler, expressMiddleware, flag, get, getContentType, hash, helmet, log, logger, methodOverride, middleware, mountExpressRouter, mqtt, patch, pgbossQueue, post, put, rateLimiter, router, serialize, serveStatic, session, setCronGlobalErrorHandler, setMqttGlobalErrorHandler, sqsQueue, timeout, trustProxy, validate };