balda 0.0.9 → 0.0.11

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';
@@ -304,11 +304,37 @@ declare const controller: (path?: string, swaggerOptions?: SwaggerRouteOptions)
304
304
  type AjvInstance = InstanceType<typeof Ajv>;
305
305
  type AjvCompileParams = Parameters<AjvInstance["compile"]>;
306
306
 
307
+ type RequestSchema = ZodType | TSchema | AjvCompileParams[0];
308
+ type ValidatedData<T extends RequestSchema> = T extends ZodType ? z.infer<T> : T extends TSchema ? Static<T> : T extends AjvCompileParams[0] ? any : any;
309
+ interface CustomValidationError {
310
+ status?: number;
311
+ message?: string;
312
+ }
313
+ interface ValidationOptions {
314
+ /**
315
+ * The schema to validate the request body against (Zod, TypeBox, or plain JSON schema)
316
+ */
317
+ body?: RequestSchema;
318
+ /**
319
+ * The schema to validate the query parameters against (Zod, TypeBox, or plain JSON schema)
320
+ */
321
+ query?: RequestSchema;
322
+ /**
323
+ * The schema to validate both body and query against (Zod, TypeBox, or plain JSON schema)
324
+ */
325
+ all?: RequestSchema;
326
+ /**
327
+ * Whether to use safe validation (returns original data if validation fails instead of throwing)
328
+ * @default false
329
+ */
330
+ safe?: boolean;
331
+ }
332
+
307
333
  type SyncOrAsync<T = void> = T | Promise<T>;
308
334
 
309
335
  interface AsyncLocalStorageContext {
310
336
  }
311
- type AsyncLocalStorageContextSetters<K extends keyof AsyncLocalStorageContext = keyof AsyncLocalStorageContext> = Record<K, (req: Request$1) => SyncOrAsync<AsyncLocalStorageContext[K]>>;
337
+ type AsyncLocalStorageContextSetters<K extends keyof AsyncLocalStorageContext = keyof AsyncLocalStorageContext> = Record<K, (req: Request) => SyncOrAsync<AsyncLocalStorageContext[K]>>;
312
338
 
313
339
  type StaticPluginOptions = {
314
340
  /**
@@ -367,28 +393,38 @@ type FilePluginOptions = {
367
393
  allowedMimeTypes?: (FileAllowedMimeType | (string & {}))[];
368
394
  };
369
395
 
370
- declare global {
371
- interface Request {
372
- params: Record<string, string>;
373
- query: Record<string, string>;
374
- }
375
- }
376
- declare class NativeRequest extends Request {
377
- }
378
-
379
396
  /**
380
397
  * The request object.
381
398
  * This is the main object that is passed to the handler function.
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
+ #private;
404
+ /**
405
+ * Creates a new request object from a Web API Request object.
406
+ * @param request - The Web API Request object to create a new request object from.
407
+ * @returns The new request object.
408
+ */
409
+ static fromRequest(request: globalThis.Request): Request;
410
+ /**
411
+ * Compiles and validates the request data against the input schema.
412
+ * @param inputSchema - The schema to validate the request data against (Zod, TypeBox, or plain JSON schema).
413
+ * @param data - The request data to validate.
414
+ * @param safe - If true, the function will return the original data if the validation fails instead of throwing an error.
415
+ * @returns The validated data.
416
+ */
387
417
  private static compileAndValidate;
388
418
  /**
389
- * Enrich native request with validation methods.
419
+ * The raw Web API Request body.
420
+ * @warning if using body parser middleware, this property will be read and the parsed body will be set to the `parsedBody` property.
421
+ * @warning this body can be read once so be careful not to use it after the body parser middleware has been applied.
422
+ */
423
+ readonly body: globalThis.Request["body"];
424
+ /**
425
+ * The parsed body of the request from the body parser middleware.
390
426
  */
391
- static enrichRequest(request: Request$1): Request$1;
427
+ parsedBody: any;
392
428
  /**
393
429
  * The context of the request. Can be augmented extending AsyncLocalStorageContext interface
394
430
  * @asyncLocalStorage middleware is required
@@ -458,40 +494,38 @@ declare class Request$1<Params extends Record<string, string> = any> extends Nat
458
494
  params: Params;
459
495
  /**
460
496
  * The query parameters of the request.
497
+ * Lazy parsed - only parses URLSearchParams when accessed
461
498
  */
462
- query: Record<string, string>;
499
+ get query(): Record<string, string>;
500
+ set query(value: Record<string, string>);
463
501
  /**
464
- * The raw body of the request. Only available for POST, PUT, PATCH and DELETE requests.
502
+ * Set the raw query string (called by server implementations)
503
+ * @internal
465
504
  */
466
- rawBody?: ArrayBuffer;
467
- private _id;
505
+ setQueryString(queryString: string): void;
468
506
  /**
469
507
  * The id of the request.
470
508
  */
471
509
  get id(): string;
472
510
  set id(value: string);
473
- /**
474
- * The parsed body of the request
475
- */
476
- body: any;
477
511
  /**
478
512
  * The validated body of the request.
479
513
  * @param inputSchema - The schema to validate the body against (Zod schema or JSON Schema).
480
514
  * @param safe - If true, the function will return the original body if the validation fails instead of throwing an error.
481
515
  */
482
- validate(inputSchema: ZodAny | AjvCompileParams[0], safe?: boolean): any;
516
+ validate<T extends RequestSchema>(inputSchema: T, safe?: boolean): ValidatedData<T>;
483
517
  /**
484
518
  * Validates the query string of the request.
485
519
  * @param inputSchema - The schema to validate the query against (Zod schema or JSON Schema).
486
520
  * @param safe - If true, the function will return undefined if the validation fails instead of throwing an error.
487
521
  */
488
- validateQuery(inputSchema: ZodAny | AjvCompileParams[0], safe?: boolean): any;
522
+ validateQuery<T extends RequestSchema>(inputSchema: T, safe?: boolean): ValidatedData<T>;
489
523
  /**
490
524
  * Validates the body and query string of the request.
491
525
  * @param inputSchema - The schema to validate against (Zod schema or JSON Schema).
492
526
  * @param safe - If true, the function will return undefined if the validation fails instead of throwing an error.
493
527
  */
494
- validateAll(inputSchema: ZodAny | AjvCompileParams[0], safe?: boolean): any;
528
+ validateAll<T extends RequestSchema>(inputSchema: T, safe?: boolean): ValidatedData<T>;
495
529
  }
496
530
 
497
531
  /**
@@ -790,7 +824,7 @@ declare class Response$1 {
790
824
  getBody(): any;
791
825
  }
792
826
 
793
- type DelHandler = (req: Request$1, res: Response$1, ...args: any[]) => any;
827
+ type DelHandler = (req: Request, res: Response$1, ...args: any[]) => any;
794
828
  /**
795
829
  * Decorator to mark an handler for a DELETE request
796
830
  * @param path - The path of the route
@@ -811,7 +845,7 @@ type DelHandler = (req: Request$1, res: Response$1, ...args: any[]) => any;
811
845
  */
812
846
  declare const del: (path: string, options?: SwaggerRouteOptions) => <T extends DelHandler>(target: any, propertyKey: string, descriptor: PropertyDescriptor) => TypedPropertyDescriptor<T>;
813
847
 
814
- type GetHandler = (req: Request$1, res: Response$1, ...args: any[]) => any;
848
+ type GetHandler = (req: Request, res: Response$1, ...args: any[]) => any;
815
849
  /**
816
850
  * Decorator to mark an handler for a GET request
817
851
  * @param path - The path of the route
@@ -832,7 +866,7 @@ type GetHandler = (req: Request$1, res: Response$1, ...args: any[]) => any;
832
866
  */
833
867
  declare const get: (path: string, options?: SwaggerRouteOptions) => <T extends GetHandler>(target: any, propertyKey: string, descriptor: PropertyDescriptor) => TypedPropertyDescriptor<T>;
834
868
 
835
- type PatchHandler = (req: Request$1, res: Response$1, ...args: any[]) => any;
869
+ type PatchHandler = (req: Request, res: Response$1, ...args: any[]) => any;
836
870
  /**
837
871
  * Decorator to mark an handler for a PATCH request
838
872
  * @param path - The path of the route
@@ -853,7 +887,7 @@ type PatchHandler = (req: Request$1, res: Response$1, ...args: any[]) => any;
853
887
  */
854
888
  declare const patch: (path: string, options?: SwaggerRouteOptions) => <T extends PatchHandler>(target: any, propertyKey: string, descriptor: PropertyDescriptor) => TypedPropertyDescriptor<T>;
855
889
 
856
- type PostHandler = (req: Request$1, res: Response$1, ...args: any[]) => any;
890
+ type PostHandler = (req: Request, res: Response$1, ...args: any[]) => any;
857
891
  /**
858
892
  * Decorator to mark an handler for a POST request
859
893
  * @param path - The path of the route
@@ -874,7 +908,7 @@ type PostHandler = (req: Request$1, res: Response$1, ...args: any[]) => any;
874
908
  */
875
909
  declare const post: (path: string, options?: SwaggerRouteOptions) => <T extends PostHandler>(target: any, propertyKey: string, descriptor: PropertyDescriptor) => TypedPropertyDescriptor<T>;
876
910
 
877
- type PutHandler = (req: Request$1, res: Response$1, ...args: any[]) => any;
911
+ type PutHandler = (req: Request, res: Response$1, ...args: any[]) => any;
878
912
  /**
879
913
  * Decorator to mark an handler for a PUT request
880
914
  * @param path - The path of the route
@@ -1318,38 +1352,6 @@ interface HelmetOptions {
1318
1352
  contentSecurityPolicy?: false | string;
1319
1353
  }
1320
1354
 
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
1355
  type LoggerOptions = Parameters<typeof pino$1>[0];
1354
1356
 
1355
1357
  interface LogOptions {
@@ -1444,7 +1446,7 @@ type CustomRateLimiterOptions = {
1444
1446
  /**
1445
1447
  * Generate a key for the rate limiter from the request (e.g. user id, email, etc.)
1446
1448
  */
1447
- key: (req: Request$1) => string;
1449
+ key: (req: Request) => string;
1448
1450
  /**
1449
1451
  * The storage strategy to use
1450
1452
  * @default "memory"
@@ -1533,6 +1535,35 @@ type TrustProxyOptions = {
1533
1535
  hop?: "first" | "last";
1534
1536
  };
1535
1537
 
1538
+ /**
1539
+ * The next function.
1540
+ * This is the function that is passed to the handler function.
1541
+ * It has a pointer to the next middleware or handler function of the middleware chain.
1542
+ */
1543
+ type NextFunction = () => SyncOrAsync;
1544
+
1545
+ interface JsonOptions {
1546
+ /**
1547
+ * The maximum size of the JSON body in bytes.
1548
+ * If the body is larger than this limit, the request will be rejected.
1549
+ * Default: 100kb
1550
+ */
1551
+ sizeLimit?: `${number}mb` | `${number}kb`;
1552
+ /**
1553
+ * If true, the JSON body will be parsed as an empty object if it is empty.
1554
+ * Default: false (body will be undefined)
1555
+ */
1556
+ parseEmptyBodyAsObject?: boolean;
1557
+ /**
1558
+ * The custom error message to return when the JSON body is too large.
1559
+ * Default: response with status 413 and body { message: "ERR_REQUEST_BODY_TOO_LARGE" }
1560
+ */
1561
+ customErrorMessage?: {
1562
+ status?: number;
1563
+ message?: string;
1564
+ };
1565
+ }
1566
+
1536
1567
  /**
1537
1568
  * Options for URL-encoded middleware
1538
1569
  */
@@ -1561,22 +1592,19 @@ type UrlEncodedOptions = {
1561
1592
  parameterLimit?: number;
1562
1593
  };
1563
1594
 
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;
1595
+ type BodyParserOptions = {
1596
+ json?: JsonOptions;
1597
+ urlencoded?: UrlEncodedOptions;
1598
+ fileParser?: FilePluginOptions;
1599
+ };
1570
1600
 
1571
1601
  type ServerPlugin = {
1602
+ bodyParser?: BodyParserOptions;
1572
1603
  cors?: CorsOptions;
1573
- json?: JsonOptions;
1574
1604
  static?: StaticPluginOptions;
1575
- fileParser?: FilePluginOptions;
1576
1605
  helmet?: HelmetOptions;
1577
1606
  cookie?: CookieMiddlewareOptions;
1578
1607
  log?: LogOptions;
1579
- urlencoded?: UrlEncodedOptions;
1580
1608
  rateLimiter?: {
1581
1609
  keyOptions?: RateLimiterKeyOptions;
1582
1610
  storageOptions?: StorageOptions$1;
@@ -1602,8 +1630,6 @@ type ServerOptions<H extends NodeHttpClient = NodeHttpClient> = {
1602
1630
  plugins?: ServerPlugin;
1603
1631
  /** The tap options to interact with the underlying server connector before it is used to listen for incoming requests */
1604
1632
  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
1633
  /**
1608
1634
  * 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
1635
  * @example
@@ -1651,11 +1677,10 @@ type ResolvedServerOptions = {
1651
1677
  controllerPatterns: string[];
1652
1678
  plugins: ServerPlugin;
1653
1679
  tapOptions: ServerTapOptions;
1654
- useBodyParser: boolean;
1655
1680
  swagger: Parameters<typeof swagger>[0] | boolean;
1656
1681
  graphql?: GraphQLOptions;
1657
1682
  };
1658
- type ServerErrorHandler = (req: Request$1, res: Response$1, next: NextFunction, error: Error) => SyncOrAsync;
1683
+ type ServerErrorHandler = (req: Request, res: Response$1, next: NextFunction, error: Error) => SyncOrAsync;
1659
1684
  interface ServerInterface {
1660
1685
  /**
1661
1686
  * Identifier for the balda server instance
@@ -1932,8 +1957,8 @@ type ServerConnectInput<H extends NodeHttpClient = NodeHttpClient> = {
1932
1957
  /** The graphql options to apply to the server */
1933
1958
  graphql?: GraphQL;
1934
1959
  } & (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;
1960
+ type ServerRouteMiddleware = (req: Request, res: Response$1, next: NextFunction) => SyncOrAsync;
1961
+ type ServerRouteHandler = (req: Request, res: Response$1) => SyncOrAsync;
1937
1962
  interface ServerRoute {
1938
1963
  /** The path for the route */
1939
1964
  path: string;
@@ -1952,7 +1977,7 @@ type ServerListenCallback = ({ port, host, url, }: {
1952
1977
  /**
1953
1978
  * Custom bun fetch call to be used as an hook inside Bun.serve method
1954
1979
  */
1955
- type CustomBunFetch = (req: Request$1, server: Bun.Server<any>) => SyncOrAsync;
1980
+ type CustomBunFetch = (req: Request, server: Bun.Server<any>) => SyncOrAsync;
1956
1981
  /**
1957
1982
  * Custom deno fetch call to be used as an hook inside Deno.serve method
1958
1983
  */
@@ -1998,39 +2023,15 @@ interface SerializeOptions {
1998
2023
  safe?: boolean;
1999
2024
  }
2000
2025
 
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
- }
2026
+ declare const serialize: <T extends RequestSchema>(schema: T, options?: SerializeOptions) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
2026
2027
 
2027
2028
  declare const validate: {
2028
2029
  (options: ValidationOptions & {
2029
2030
  customError?: CustomValidationError;
2030
2031
  }): (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;
2032
+ query(schema: RequestSchema, customError?: CustomValidationError): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
2033
+ body(schema: RequestSchema, customError?: CustomValidationError): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
2034
+ all(schema: RequestSchema, customError?: CustomValidationError): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
2034
2035
  };
2035
2036
 
2036
2037
  /**
@@ -2207,6 +2208,25 @@ declare class BaseQueue {
2207
2208
  protected readonly logger: pino.Logger<string, boolean>;
2208
2209
  }
2209
2210
 
2211
+ declare class BullMQPubSub implements GenericPubSub {
2212
+ private queues;
2213
+ private workers;
2214
+ private bullmqClient;
2215
+ publish<TPayload>(topic: string, payload: TPayload, options?: PublishOptions<"bullmq">): Promise<{
2216
+ id: string;
2217
+ }>;
2218
+ subscribe<TPayload>(topic: string, handler: (payload: TPayload) => Promise<void>): Promise<void>;
2219
+ private getQueue;
2220
+ private getBullMQClient;
2221
+ publishWithConfig<TPayload>(topic: string, payload: TPayload, options?: PublishOptions<"bullmq">, queueConfig?: BullMQQueueOptions): Promise<{
2222
+ id: string;
2223
+ }>;
2224
+ subscribeWithConfig<TPayload>(topic: string, handler: (payload: TPayload) => Promise<void>, queueConfig?: BullMQQueueOptions): Promise<void>;
2225
+ private getQueueWithConfig;
2226
+ private getQueueKey;
2227
+ private getWorkerKey;
2228
+ }
2229
+
2210
2230
  declare class PGBossPubSub implements GenericPubSub {
2211
2231
  private boss;
2212
2232
  private createdQueues;
@@ -2271,141 +2291,6 @@ interface QueueProvider {
2271
2291
  }
2272
2292
  type QueueProviderKey = keyof QueueProvider;
2273
2293
 
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
2294
  type QueueOptionsForProvider<P extends BuiltInProviderKey> = P extends "sqs" ? SQSQueueOptions : P extends "bullmq" ? BullMQQueueOptions : P extends "pgboss" ? PGBossQueueOptions : never;
2410
2295
  /**
2411
2296
  * TypedQueue for built-in providers (sqs, bullmq, pgboss)
@@ -2556,6 +2441,122 @@ declare function pgbossQueue<TPayload>(topic: string, options?: PGBossQueueOptio
2556
2441
  */
2557
2442
  declare function createQueue<TPayload, TOptions = Record<string, unknown>>(topic: string, pubsub: GenericPubSub<TPayload>): CustomTypedQueue<TPayload, TOptions>;
2558
2443
 
2444
+ /**
2445
+ * Options for BullMQ configuration
2446
+ * @param options - The options for BullMQ
2447
+ * @param errorHandler - Custom error handler that will be triggered when a job fails, for logging or debug purposes
2448
+ */
2449
+ type BullMQConfigurationOptions = ConstructorParameters<typeof Queue>[1] & {
2450
+ errorHandler?: (job: Job, error: Error) => SyncOrAsync;
2451
+ };
2452
+ declare class BullMQConfiguration {
2453
+ static options: BullMQConfigurationOptions;
2454
+ }
2455
+ /**
2456
+ * Define globally custom BullMQ configuration
2457
+ * @param options - The BullMQ configuration options
2458
+ */
2459
+ declare const defineBullMQConfiguration: (options: BullMQConfigurationOptions) => void;
2460
+
2461
+ type CustomQueueConfiguration = GenericPubSub;
2462
+
2463
+ type PGBossConfigurationOptions = {
2464
+ connectionString?: string;
2465
+ boss?: unknown;
2466
+ errorHandler?: (error: Error) => SyncOrAsync;
2467
+ };
2468
+ declare class PGBossConfiguration {
2469
+ static options: PGBossConfigurationOptions;
2470
+ }
2471
+ declare const definePGBossConfiguration: (options: PGBossConfigurationOptions) => void;
2472
+
2473
+ type SQSConfigurationOptions = {
2474
+ client?: SQSClientConfig;
2475
+ consumer?: {
2476
+ batchSize?: number;
2477
+ visibilityTimeout?: number;
2478
+ waitTimeSeconds?: number;
2479
+ queueUrlMap: Record<string, string>;
2480
+ };
2481
+ errorHandler?: (error: Error) => SyncOrAsync;
2482
+ };
2483
+ declare class SQSConfiguration {
2484
+ static options: SQSConfigurationOptions;
2485
+ }
2486
+ declare const defineSQSConfiguration: (options: SQSConfigurationOptions) => void;
2487
+
2488
+ declare class QueueManager {
2489
+ static map: Map<QueueProviderKey, GenericPubSub>;
2490
+ static getProvider<P extends QueueProviderKey>(provider: P): GenericPubSub<P>;
2491
+ static setProvider(provider: QueueProviderKey, pubsub: GenericPubSub<QueueProviderKey>): void;
2492
+ }
2493
+
2494
+ /**
2495
+ * Main entry point to define the queue configuration, meant to be called only once in the application bootstrap
2496
+ * @bullmq - The BullMQ configuration options
2497
+ * @pgboss - The PGBoss configuration options
2498
+ * @sqs - The SQS configuration options
2499
+ * @string - The custom queue provider name with it's PubSub implementation
2500
+ * @example
2501
+ * defineQueueConfiguration({
2502
+ * bullmq: {
2503
+ * connection: {
2504
+ * host: "127.0.0.1",
2505
+ * password: "root",
2506
+ * username: "default",
2507
+ * db: 0,
2508
+ * },
2509
+ * },
2510
+ * pgboss: {
2511
+ * connectionString: "postgres://root:root@localhost:5432/database",
2512
+ * },
2513
+ * sqs: {
2514
+ * client: { region: "us-east-1" },
2515
+ * },
2516
+ * custom: new CustomPubSub(),
2517
+ * });
2518
+ * @example
2519
+ * defineQueueConfiguration({
2520
+ * custom: new CustomPubSub(),
2521
+ * });
2522
+ */
2523
+ declare const defineQueueConfiguration: (options: {
2524
+ bullmq?: Parameters<typeof defineBullMQConfiguration>[0];
2525
+ pgboss?: Parameters<typeof definePGBossConfiguration>[0];
2526
+ sqs?: Parameters<typeof defineSQSConfiguration>[0];
2527
+ } & { [key in Exclude<QueueProviderKey, "bullmq" | "pgboss" | "sqs">]?: CustomQueueConfiguration; }) => void;
2528
+
2529
+ type QueueHandler = (payload: unknown) => Promise<void>;
2530
+ type TypedQueueRegistration = {
2531
+ name: string;
2532
+ topic: string;
2533
+ handler: QueueHandler;
2534
+ provider: BuiltInProviderKey;
2535
+ queueOptions?: unknown;
2536
+ };
2537
+ type CustomQueueRegistration = {
2538
+ name: string;
2539
+ topic: string;
2540
+ handler: QueueHandler;
2541
+ pubsub: GenericPubSub;
2542
+ };
2543
+ declare class QueueService {
2544
+ static typedQueueSubscribers: Map<string, TypedQueueRegistration>;
2545
+ static customQueueSubscribers: Map<string, CustomQueueRegistration>;
2546
+ /**
2547
+ * Factory function for creating handler instances.
2548
+ * Can be overridden to provide custom dependency injection.
2549
+ * @default Creates new instance using constructor
2550
+ */
2551
+ static instanceFactory: (ctor: Function) => object;
2552
+ static registerTypedQueue(name: string, topic: string, handler: QueueHandler, provider: BuiltInProviderKey, queueOptions?: unknown): void;
2553
+ static registerCustomQueue(name: string, topic: string, handler: QueueHandler, pubsub: GenericPubSub): void;
2554
+ static run(): Promise<void>;
2555
+ static massiveImportQueues(queueHandlerPatterns: string[], options?: {
2556
+ throwOnError?: boolean;
2557
+ }): Promise<void>;
2558
+ }
2559
+
2559
2560
  /**
2560
2561
  * The logger instance, can be overridden by the `defineLoggerConfig` function
2561
2562
  */
@@ -3167,30 +3168,12 @@ declare function createExpressAdapter(server: {
3167
3168
  use(pathOrMiddleware: string | RequestHandler | Router$1, maybeMiddleware?: RequestHandler | Router$1): void;
3168
3169
  };
3169
3170
 
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
3171
  /**
3182
3172
  * Sets common HTTP security headers
3183
3173
  * @param options Helmet options (all optional)
3184
3174
  */
3185
3175
  declare const helmet: (options?: HelmetOptions) => ServerRouteMiddleware;
3186
3176
 
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
3177
  /**
3195
3178
  * Logs the request and response of the handler, can be set both on a specific route or on a global middleware.
3196
3179
  * @warning Only json objects and strings are logged from the request and response.
@@ -3259,18 +3242,6 @@ declare const timeout: (options: TimeoutOptions) => ServerRouteMiddleware;
3259
3242
  */
3260
3243
  declare const trustProxy: (options?: TrustProxyOptions) => ServerRouteMiddleware;
3261
3244
 
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
3245
  type PolicyProvider = {
3275
3246
  [K: string]: (...args: any[]) => Promise<boolean> | boolean;
3276
3247
  };
@@ -3304,4 +3275,4 @@ declare const createPolicyDecorator: <T extends Record<string, PolicyProvider>>(
3304
3275
  */
3305
3276
  declare const router: ClientRouter;
3306
3277
 
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 };
3278
+ 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 };